
As noted, IO is not strict in the value x, only in the operation that
generates x. However, should you desire strictness in a generic way, it
would be trivial to model a transformer monad to provide it.
E.g.
data StrictT m a = StrictT (m a)
runStrictT :: StrictT m a -> m a
runStrictT (StrictT op) = op
class (Monad m) => Monad (StrictT m a) where
return x = StrictT (return x)
(StrictT op) >>= f = op >>= \ a -> a `seq` StrictT (f a)
On Sat, Jan 21, 2012 at 9:29 AM, Victor S. Miller
The "do" notation translates
do {x <- a;f} into
a>>=(\x -> f)
However when we're working in the IO monad the semantics we want requires that the lambda expression be strict in its argument. So is this a special case for IO? If I wanted this behavior in other monads is there a way to specify that?
Victor
Sent from my iPhone _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe