[Haskell-beginners] deep seq and bang patterns

Daniel Fischer daniel.is.fischer at googlemail.com
Tue Dec 25 20:08:41 CET 2012


On Dienstag, 25. Dezember 2012, 19:07:33, Emmanuel Touzery wrote:
> Thank you. I think you are as clear as possible, and complete.
> I do wonder though, isn't there an annotation or technique that would force
> the parameters of a constructor to be evaluated to WHNF when the
> constructor is evaluated?

That's what strictness annotations do.

> In my case i believe the constructor is evaluated
> immediately because it's in a do block of the IO monad.

IO is still nonstrict in the values,

data Strict = S !Int

*Strict> do { putStrLn "Strictly"; return (S undefined); }
Strictly
*Strict> do { putStrLn "Strictly"; return $! (S undefined); }
Strictly
*** Exception: Prelude.undefined

returning a value doesn't force its evaluation to WHNF.




More information about the Beginners mailing list