[Haskell-cafe] Re: Fwd: Re: Simple game: a monad for each player
apfelmus at quantentunnel.de
Thu Apr 15 03:53:50 EDT 2010
> Okay, I start to understand better...
> Just, Heinrich, how would implement the mapMonad function in terms of the
> operational package?
> You just shown the signature.
Ah, that has to be implemented by the library, the user cannot implement
this. Internally, the code would be as Bertram suggests:
mapMonad :: (Monad m1, Monad m2)
=> (forall a . m1 a -> m2 a)
-> ProgramT instr m1 a -> ProgramT instr m2 a
mapMonad f (Lift m1) = Lift (f m1)
mapMonad f (Bind m k) = Bind (mapMonad f m) (mapMonad f . k)
mapMonad f (Instr i) = Instr i
I was musing that every instance of MonadTrans should implement this
Also note that there's a precondition on f , namely it has to respect
the monad laws:
f (m >>= k) = f m >>= f . k
f return = return
f :: Identity a -> IO a
f x = launchMissiles >> return (runIdentity x)
violates this condition.
More information about the Haskell-Cafe