[Haskell-cafe] Remember the future
Matthew Naylor
mfn-haskell-cafe at cs.york.ac.uk
Sat Aug 18 12:07:06 EDT 2007
Hi Dan,
> > import Control.Monad.State
>
> > test = do
> > put $ x+1
> > x <- return 1
> > return undefined
>
> > go = execState test undefined
I'd just like to point out that you can do something similar without
mdo. For example, you can define a monad with newVar, readVar, and
writeVar such that running the following results in 2.
test = do x <- newVar
y <- newVar
valx <- readVar x
writeVar y (valx+1)
writeVar x 1
valy <- readVar y
return valy
(As you probably know, the previous two Monad.Reader issues include
two different examples -- assembler and circuit description -- of
circular programming in a monad.)
Matt.
More information about the Haskell-Cafe
mailing list