In doing some reading lately I came upon an article that may be enlightening on the subject of the purpose of dreaming, which came up in another thread in this forum recently. The following is an excerpt of that piece, chapter 8 of Stephen LaBerge's book Lucid Dreaming. The full chapter can be found online here.
All right, you might say, so that's why we have Quiet Sleep, but why did Active Sleep evolve and with it dreaming? Certainly, there must have been very good reasons for it, since this state has many disadvantages. For one, your brain uses much more energy during dreaming than it does while awake or in Quiet Sleep. For another, there is the fact that the body is paralyzed while you are dreaming, significantly increasing the sleeper's vulnerability. In fact, the amount of dreaming sleep for a given species is directly proportional to the degree of safety from predators; the more dangerous life is, the less a species can afford to dream.
Given these drawbacks, Active Sleep must have offered particularly useful advantages to the mammals of one hundred and thirty million years ago. We can guess one advantage if we remember that this was just the point in evolutionary history when mammalian mothers gave up laying eggs in favor of bearing live young instead. So what advantages might Active Sleep have offered to our ancestral mothers? The answer can be seen, I think, if you recall that egg-hatched lizards or birds break out of their own shells already sufficiently developed to survive on their own if necessary. Viviparous offspring, of which the human baby provides an unexcelled example, are, on the contrary, less developed at birth and often completely, helpless. Viviparous infants have to get through a great deal of learning and development, especially of the brain, in the first few weeks, months, and years of life.
In contrast to the hour and a half an adult spends in REM sleep each night, a new-born baby, who sleeps sixteen to eighteen hours a day is likely to spend 50% of all this time-- as much as nine hours a day--dreaming! The fact that the amount and proportion of REM sleep decreases throughout life suggested to several dream researchers  that REM sleep may play an important role in the development of the infant brain, providing an internal source of intense stimulation which would facilitate the maturation of the infant's nervous system as well as help in preparing the child for the limitless world of stimulation it will soon have to face.
The foremost French sleep researcher, Professor Michel Jouvet, of the University of Lyon, has proposed a similar function for Active Sleep: according to him, dreaming permits the testing and practicing of genetically programmed (i.e., instinctual) behaviors without the consequences of overt motor responses--thanks to the paralysis of this Paradoxical state of sleep. So the next time you see a newborn baby girl or boy smiling in their sleep, don't be surprised if they turn out to be perfecting their perfect smile to charm a heart they are yet to meet!
Well then, so now we know why babies dream. But if that were all there is to it, why wouldn't REM sleep completely disappear by adulthood? Well it might, except that there does seem to be something more to it, providing adults with a good reason to continue to dream. The reason is this: Active Sleep has indeed been found to be intimately involved with learning and memory.
The evidence connecting the dream state with learning and memory is of two kinds: the most direct evidence is an extensive body of research indicating that learning tasks that require significant concentration or the acquisition of unfamiliar skills is followed by increased REM sleep. The second type of evidence is less direct but still quite convincing: many studies have shown that memory for certain types of learning is impaired by subsequent REM deprivation. Psychologists distinguish two varieties of learning: prepared and unprepared learning. Prepared learning is easy and quickly acquired while unprepared learning is difficult and only slowly mastered with great effort. According to Boston psychiatrists Dr. Ramon Greenberg and Dr. Chester Pearlman, it is only unprepared learning that is REM- dependent. In of their experiments, which involved rats, they easily learned that cheese was located behind one of two doors--and an electric shock behind the other: this is called "simple position" learning, and most animals are well equipped for it. If on the other hand, the position of reward and punishment are reversed on successive trials, so that each time shock is to be found where cheese was on the previous trial and vice versa, most animals find it difficult (or impossible) to work out this more complex pattern and learn where to expect what; in other words, for rats, "successive position reversal" is an instance of unprepared learning.
After Greenberg and Pearlman subjected rats to these two varieties of task, they deprived them of REM sleep and then re-tested the rats for learning. They reported that while simple position learning was unimpaired by REM deprivation, successive position reversal was "markedly" impaired. "This finding is noteworthy" they remarked, "because successive position reversal is a task which clearly distinguishes the learning capacities of species with REM sleep (mammals) from those without it (fish)." The implication is that REM sleep makes more complex learning possible than would otherwise be the case.
Greenberg and Pearlman conclude that dreaming sleep "appears in species that show increasing abilities to assimilate unusual information into the nervous system." They suggest that the evolutionary development of the dream state "has made possible the increasingly flexible use of information in the mammalian family. That this process occurs during sleep seems to fit with current thinking about programming and reprogramming of information processing systems. Thus, several authors have pointed out the advantage of a separate mechanism for reprogramming the brain in order to avoid interference with ongoing functions." 
One of these authors is Christopher Evans, whose computer- analogy theory of dreams is presented in his recent book, Landscapes of the Night: How and Why We Dream. The late Dr. Evans was an English psychologist with an abiding interest in computers who proposed that dreaming is the brain-computer's "off-line" time when the mind is assimilating the experiences of the day and at the same time updating its programs.
Not only is dreaming associated with learning and memory, but it also appears to play a somewhat broader role in the processing of information in the nervous system, including coping with traumatic experiences and emotional adjustment. The dream state has also been proposed as a restorative for mental functioning; according to Professor Ernest Hartmann, REM sleep helps us to adapt to our environments by improving our mood, memory, and other cognitive functioning through restoring certain neurochemicals that are depleted in the course of waking mental activity. 
Dreaming sleep has also been shown to play a general role in reducing brain excitability.  It can have a favorable effect on our moods, making us, for example, less irritable. Janet Dallet, in a dissertation, has reviewed a number of theories of dream function, concluding that "contemporary theories tend to focus on the function of environmental mastery, viewed from one of three perspectives: (a) problem solving (b) information processing, or (c) ego consolidation." 
Finally, psychologist Ernest Rossi has attributed to dreams a developmental function:
In dreams we witness something more than mere wishes; we experience dramas reflecting our psychological state and the process of change taking place in it. Dreams are a laboratory for experimenting with changes in our psychic life...This constructive or synthetic approach to dreams can be clearly stated: Dreaming is an endogenous process of psychological growth, change and transformation. 
It might be said of the diverse theories of dream function that they all are partly right and they all are partly wrong: right in so far as they say what a function of dreaming is, and wrong to the extent that they say what the function of dreaming is. [...]
Putting aside, for the moment, the question of the special functions of dreaming, let us ask what is the most basic or general function that dreaming is likely to serve. Since dreaming is an activity of the brain, we must first ask what function brain activity serves? And because the most general biological purpose of living organisms is survival, this must also be the most general biological answer to the purpose of brain activity. The brain fosters survival by regulating the organism's transactions with the world and with itself. These latter transactions would perhaps be best achieved in the dream state, when sensory information from the external world is at its minimum.