[Haskell-beginners] reverse [1..]
Emmanuel Touzery
etouzery at gmail.com
Tue Dec 18 15:28:07 CET 2012
> Hi,
>
> When I run this code in ghci:
>
> reverse [1..]
>
> I get:
>
> <interactive>: out of memory (requested 2097152 bytes)
>
> Can anyone explain this behaviour?
>
It is an infinite list you are trying to reverse. This cannot terminate.
Which is the first element you would expect to see in the result?
Those two will finish:
reverse $ take 100 [1..]
reverse [1..100]
Emmanuel
More information about the Beginners
mailing list