State monads don't respect the monad laws in Haskell

Alastair Reid reid@cs.utah.edu
15 May 2002 01:09:07 +0100


Hal Daume <hdaume@ISI.EDU> writes:
> [seq is] useful for:
> 
> debug :: Show a => a -> a
> debug x = unsafePerformIO (hPutStrLn stderr (show x)) `seq` x
> 
> (Presumably "trace" is defined similarly)
> 
> One may ask the question: what is seq useful for not in conjunction with
> unsafePerformIO, other than efficiency.  That, I don't know the answer to.


Of course, this can be defined without seq:

> debug :: Show a => a -> a
> debug x = unsafePerformIO (hPutStrLn stderr (show x) >> return x)

-- 
Alastair Reid        Reid Consulting (UK) Ltd