[Haskell-cafe] Shouldn't this loop indefinitely => take (last [0..]) [0..]

Olivier Boudry olivier.boudry at gmail.com
Thu Apr 3 17:27:17 EDT 2008

Hi all,

If you compile and run this:

    main = do
      putStrLn $ show $ take (last [0..]) [0..]

or simply run:

    take (last [0..]) [0..]

in ghci, it first hang for about one minute and then starts to generate an
infinite list. I was expecting "last [0..]" to never produce a value and the
"take" function to never take from the [0..] list.

I found that line of code in a friend's "Skype Message", lauched it in ghci
and forgot it. When I came back to my ghci window a couple minutes later it
was listing numbers, which was really unexpected.

If I just run "last [0..]" it doesn't return a value and my computer will
quickly start to paginate to death. Am I missing something? Some laziness
magic? Rewrite rules?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080403/9198713b/attachment.htm

More information about the Haskell-Cafe mailing list