Missing MaybeT MonadFix instance

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Fri Apr 8 18:43:33 CEST 2011

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.


(and I agree that the error can't happen)


More information about the Libraries mailing list