DeepSeq.lhs [was: Re: [Haskell] Force evaluation]

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Wed Dec 8 11:05:04 EST 2004


Dean Herington wrote:

 >> deepSeq :: DeepSeq a => a -> b -> b

I should point out that deepSeq with this type is the composition of two 
simpler operations:

    deepSeq = seq . eval where eval :: DeepSeq a => a -> a

eval ties a demand for a value to a demand for all its subvalues, while 
seq ties a demand for a value to a demand for another value of an 
unrelated type.

Of course you can define eval x = x `deepSeq` x instead, so it's largely 
a matter of taste.

 >>  instance  DeepSeq (IO a)  where  deepSeq = seq

This is an interesting instance (which is not to say I think it's 
wrong). It means the original poster's code won't work. He wanted to write

    foo <- eval makeFoo `catch` \e -> defaultFoo

but makeFoo has a monadic type, so eval makeFoo === makeFoo.

-- Ben



More information about the Haskell mailing list