
Limestraƫl wrote:
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 function. 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 For instance, f :: Identity a -> IO a f x = launchMissiles >> return (runIdentity x) violates this condition. Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com