[Haskell-cafe] couple of questions on monads
iavor.diatchki at gmail.com
Mon Oct 13 19:02:32 EDT 2008
On Mon, Oct 13, 2008 at 3:16 PM, Stephen Hicks <sdh33 at cornell.edu> wrote:
> 2008/10/13 Daryoush Mehrtash <dmehrtash at gmail.com>:
>> Is there a write up on what makes an implementation lazy vs strict?
> I would be interested in seeing this, too!
Typically it has to do with the strictness of the "bind" operation.
Here is an example to illustrate the difference.
evalState (undefined >> return True) undefined
When you evaluate this in the context of Control.Monad.State, the
result is "True", while if you evaluate it in the context of
Control.Monad.State.Strict you will get "undefined".
It may be interesting to compare MTL's approach to what's done in
monadLib (another monad transformer library). In monadLib,
transformers like state inherit the strictness of their bind operation
from the underlying monad. There are two base level monads: Id, which
is lazy, and Lift which is strict. So to get a strict state monad in
monadLIb, you would write "StateT s Lift", and to get the lazy version
you would use "StateT s Id".
Hope that this helps,
More information about the Haskell-Cafe