Missing MaybeT MonadFix instance

Ross Paterson ross at soi.city.ac.uk
Fri Apr 8 15:50:58 CEST 2011


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, 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.

I see IdentityT is also missing a MonadFix instance, which is easily
added:

instance (MonadFix m) => MonadFix (IdentityT m) where
    mfix f = IdentityT (mfix (runIdentityT . f))



More information about the Libraries mailing list