
Hello Emanuel,
Here's the excerpt of the "reverse" function in GHC-List (
-- | 'reverse' @xs@ returns the elements of @xs@ in reverse order.--
@xs@ must be finite.reverse :: [a] -> [a]#ifdef
USE_REPORT_PRELUDEreverse = foldl (flip (:))
[]#elsereverse 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.
On Tue, Dec 18, 2012 at 9:24 AM, Emanuel Koczwara wrote: 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