[Haskell-cafe] Re: A question about mfix
voigt at tcs.inf.tu-dresden.de
Wed Jul 30 02:37:44 EDT 2008
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
> (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
((),S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S ........
I think that proves the point.
Dr. Janis Voigtlaender
mailto:voigt at tcs.inf.tu-dresden.de
More information about the Haskell-Cafe