Re: Missing MaybeT MonadFix instance

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))

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

Hi Ross, On Apr 8, 2011, at 6:50 AM, Ross Paterson wrote:
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.
For whatever it's worth, modulo names and type-wrappers, your definition above is the same as Equation 4.36 (pg. 54) of http://bit.ly/fGJMVD, and Proposition 4.9.1 (on the same page) establishes that it's a good definition. -Levent.
participants (3)
-
Bertram Felgenhauer
-
Levent Erkok
-
Ross Paterson