[Haskell-cafe] infinite lists

Matthew Brecknell haskell at brecknell.org
Tue Mar 27 06:02:18 EDT 2007


Matthias Fischmann:
> g = do
>     n <- randomRIO (0,5)
>     let l = replicate n '*'
>         i | null l = []
>           | otherwise = join $ repeat l
>     print (take 12 i)

If you had written (cycle l) instead of (join $ repeat l), you would
have figured it out much quicker. :-)

Prelude> cycle []
*** Exception: Prelude.cycle: empty list



More information about the Haskell-Cafe mailing list