J.A. Hadfield, in his book Dreams and Nightmares (Pelican 1954), puts forward what he calls a biological theory of dreams. He says the function of dreams is that, by reproducing difficult or unsolved situations or experiences, the dream aids a solving or resolution of the problems. He gives the example of a man climbing a cliff who slips fractionally. He then may dream of actually falling and waking terrified. Subsequently the dream recurs, but in each he tries out a different behaviour, such as clasping for a branch, until he manages to act appropriately to avert the disaster. He sums up by saying dreams stand in the place of experience. They make us relive areas of anxious or difficult experience. They thus help problem solving. But they not only look back at past behaviour, they act just like thinking in considering future plans and needs.
[1]