Janis Voigtlaender wrote:
Wei Hu wrote:
Thanks for pointing out the sharing part. My original question is
still unanswered: for lazy monads, can we give such a general mfix
definition?
...
(Constructing an explicit counterexample is left as an exercise ;-)
Oh, I couldn't resist to do my own exercise ...
import Control.Monad.Fix
import Control.Monad.State.Lazy
data Nat = S Nat | Z deriving Show
tick :: State Nat ()
tick = get >>= put . S
test1 = runState (mfix (const tick)) Z
test2 = runState (mfix (const tick)) Z
where mfix f = (mfix f) >>= f
Now:
*Main> test1
((),S Z)
*Main> test2
((),S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S ........
I think that proves the point.
Ciao, Janis.
--
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:[EMAIL PROTECTED]
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe