It is not rare for a composer or songwriter to be struck with a melodic inspiration and then to wonder who wrote that melody. I believe that Paul McCartney in an interview has told of waking up with one of his now-famous melodies, playing it on the piano, and asking who wrote it.