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

Don Stewart dons at galois.com
Thu Apr 3 17:34:46 EDT 2008


olivier.boudry:
>    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 can't reproduce this with ghc 6.8.2 on a 64 bit arch, both just sit
running in constant space, at full cpu.

Are you perhaps constraining it to an Int type somewhere (so that [0..]
terminates at maxBound)? I.e. this  kind of thing:

    Prelude> last [1..] :: Int8
    127

but for maxBound on Int32?

-- Don


More information about the Haskell-Cafe mailing list