[Haskell-cafe] Re: strict Haskell dialect

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Sat Feb 4 05:50:48 EST 2006


Chris Kuklewicz wrote:
> Weak uses seq to achieve WHNF for it's argument
> 
>> newtype Weak a = WeakCon {runWeak :: a}
>> mkWeak x = seq x (WeakCon x)
>> unsafeMkWeak x = WeakCon x

This doesn't actually do what you think it does. mkWeak and unsafeMkWeak are 
the same function.

     mkWeak 123 = seq 123 (WeakCon 123) = WeakCon 123
     unsafeMkWeak 123 = WeakCon 123
     mkWeak _|_ = seq _|_ (WeakCon _|_) = _|_
     unsafeMkWeak _|_ = WeakCon _|_ = _|_

To quote John Meacham:

| A quick note,
| x `seq` x
| is always exactly equivalant to x. the reason being that your seq
| would never be called to force x unless x was needed anyway.
|
| I only mention it because for some reason this realization did not hit
| me for a long time and once it did a zen-like understanding of seq
| (relative to the random placement and guessing method I had used
| previously) suddenly was bestowed upon me.

I remember this anecdote because when I first read it, a zen-like 
understanding of seq suddenly was bestowed upon /me/. Maybe it should be in 
the docs. :-)

-- Ben



More information about the Haskell-Cafe mailing list