-- | 'reverse' @xs@ returns the elements of @xs@ in reverse order. -- @xs@ must be finite. reverse :: [a] -> [a] #ifdef USE_REPORT_PRELUDE reverse = foldl (flip (:)) [] #else reverse l = rev l [] where rev [] a = a rev (x:xs) a = rev xs (x:a) #endif
Reversing an infinite list, Haskell will try to reach the end of the list until it runs out of memory.
I don't thing it's doable lazily.
Hi,
When I run this code in ghci:
reverse [1..]
I get:
<interactive>: out of memory (requested 2097152 bytes)
Can anyone explain this behaviour?
Emanuel
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners