
Ross Paterson wrote:
On Fri, Apr 01, 2011 at 08:51:52PM -0400, Job Vranish wrote:
Is there a particular reason that the transformers version of the MaybeT monad does not have a MonadFix instance?
I don't think so. The original MaybeT package had an instance
instance (MonadFix m) => MonadFix (MaybeT m) where -- I hope this is correct. At a minimum, it typechecks. mfix f = MaybeT (mfix (maybe (return Nothing) (runMaybeT . f)))
which would loop if f returned Nothing
In fact it loops regardless of f. Prelude Control.Monad.Maybe Control.Monad.Identity ghci> runIdentity $ runMaybeT $ mfix undefined
while your instance, which is equivalent to
instance (MonadFix m) => MonadFix (MaybeT m) where mfix f = MaybeT (mfix (runMaybeT . f . unJust)) where unJust = fromMaybe (error "mfix MaybeT: Nothing")
is compatible with the MonadFix instance for Maybe, so it should probably go in.
+1 (and I agree that the error can't happen) Bertram