[Haskell-cafe] Monads, do and strictness
David Barbour
dmbarbour at gmail.com
Sat Jan 21 19:01:00 CET 2012
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
<victorsmiller at gmail.com>wrote:
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120121/5540e2f7/attachment.htm>
More information about the Haskell-Cafe
mailing list