transformers: remove instance MonadFix ExceptT and ErrorT
Henning Thielemann
schlepptop at henning-thielemann.de
Tue Aug 12 09:13:21 UTC 2014
I propose to remove the MonadFix instance for the ExceptT transformer,
because it gives the illusion that it can handle exceptions, which it
cannot.
The current implementation is:
instance (MonadFix m) => MonadFix (ExceptT e m) where
mfix f = ExceptT $ mfix $ \ a -> runExceptT $ f $ case a of
Right x -> x
Left _ -> error "mfix ExceptT: Left"
You see, that it cannot handle the exception case. Whenever someone
needs an mfix on ExceptT I strongly suggest that he first handles the
exception, thus turning (ExceptT e m a) into plain (m a) and then calls
'mfix' only on (m a).
I further propose to declare the MonadFix instance as non-implementable
in a way suggested in [1]:
class NoMonadFix m where
instance (NoMonadFix m) => MonadFix (ExceptT e m) where
mfix = error "unimplementable"
where no instance of NoMonadFix exist and NoMonadFix is not exported.
Whenever someone tries to call 'mfix' on 'ExceptT e m' he will get the
type error, that a NoMonadFix instance on 'm' is missing and he will not
be able to add it.
[1] http://ghc.haskell.org/trac/ghc/ticket/9334#comment:9
More information about the Libraries
mailing list