[Haskell-cafe] Generating a random list

Milos Hasan mhasan at cs.cornell.edu
Sat Mar 1 16:53:52 EST 2008

> It is definitely the strictness analyzer biting you here.  In ghci,
> the behavior of these two programs is identical (stack overflow).  As
> kalman said, if you replate sum with foldl' (+) 0 in each of these
> programs, the behavior is still identical (correct).
OK, I could replicate that result. Awesome, thanks a lot!

> As a side note, one of the monad laws is this:
>     return x >>= f  =  f x
> So your two programs are semantically equivalent (there's nothing
> about IO that forces the evaluation of the list).
OK, thanks, this is an important point. So maybe I should have done this?

main = print $ foldl1' (+) $! take 1000000 randFloats

My intuition tells me that the $! (and `seq`) just reduces one level (to 
WHNF?). If so, is there a way to force complete evaluation (so that 
nothing is reducible anymore)?


More information about the Haskell-Cafe mailing list