[Haskell-cafe] State monad strictness - how?
Iavor Diatchki
iavor.diatchki at gmail.com
Thu Jan 11 00:51:38 EST 2007
Hello,
On 1/10/07, Ross Paterson <ross at soi.city.ac.uk> wrote:
> > There is no such distinction in monadLib. The state transformer
> > inherits its behavior from the underlying monad. For example: StateT
> > Int IO is strict, but StatT Int Id is lazy. One way to get a strict
> > state monad with monadLib is like this:
> > [strict pseudo-monad]
>
> This (like StateT) gives you strictness in the pair, but doesn't give
> the strictness in the state that the original poster wanted.
Once we have this kind of strictness, then the programmer has control
over the state.
For example, they can define:
setStrict x = seq x (set x)
ex3 = runLift $ runState 2 $ setStrict undefined >> return 5
ex4 = runId $ runState 2 $ setStrict undefined >> return 5
In these examples "ex3 == undefined" but "ex4 = (5,undefined)".
-Iavor
More information about the Haskell-Cafe
mailing list