[Haskell-beginners] reverse [1..]
Jonathan Rioux
rioux.jonathan at gmail.com
Tue Dec 18 15:33:49 CET 2012
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 <poczta at emanuelkoczwara.pl
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121218/bc4664f7/attachment.htm>
More information about the Beginners
mailing list