[Haskell-cafe] Monads, do and strictness

Yves Parès yves.pares at gmail.com
Sun Jan 22 00:20:56 CET 2012


> (StrictT op) >>= f = StrictT (op >>= \ x -> x `seq` runStrictT (f x))

Are you sure? Here you evaluate the result, and not the computation itself.
Wouldn't it be:

(StrictT op) >>= f  = op ` seq` StrictT (op >>= \x -> runStrictT (f x))

??

2012/1/21 David Barbour <dmbarbour at gmail.com>

> On Sat, Jan 21, 2012 at 10:08 AM, Roman Cheplyaka <roma at ro-che.info>wrote:
>
>> * David Barbour <dmbarbour at gmail.com> [2012-01-21 10:01:00-0800]
>> > 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.
>>
>> Again, that wouldn't be a monad transformer, strictly speaking, because
>> "monads" it produces violate the left identity law.
>>
>
> It meets the left identity law in the same sense as the Eval monad from
> Control.Strategies.
>
> http://hackage.haskell.org/packages/archive/parallel/3.1.0.1/doc/html/src/Control-Parallel-Strategies.html#Eval
>
> That is, so long as values at each step can be evaluated to WHNF, it
> remains true that `return x >>= f` = f x.
>
> I did mess up the def of >>=. I think it should be:
>   (StrictT op) >>= f = StrictT (op >>= \ x -> x `seq` runStrictT (f x))
>
> But I'm not interested enough to actually pull out an interpreter and
> test...
>
> Regards,
>
> Dave
>
>
> _______________________________________________
> 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/20120122/d1d88ad9/attachment.htm>


More information about the Haskell-Cafe mailing list