[Haskell-cafe] Correct usage of MonadError, ErrorT?
andrew at pimlott.net
Mon Jan 30 22:32:07 EST 2006
On Tue, Jan 31, 2006 at 03:00:41PM +1300, Daniel wrote:
> I've got some functions in MonadError with different Error types. I
> would like to map errors of one Error type onto the other Error type.
> It seems that the only facility for doing this is mapErrorT, but that
> seems to force me to work in ErrorT rather than any old instance of
What type would your mapError have? The first idea that comes to mind
mapError :: (MonadError e1 m1, MonadError e2 m2) =>
(e1 -> e2) -> m1 a -> m2 a
The problem here is that m1 and m2 have no relation--m1 could be IO and
m2 (Either e2)! Not surprisingly, we can't implement that. So what
relation do you want between m1 and m2? The only one I can think of is
that m1 and m2 are ErrorT transforms of the same inner monad. In this
case mapErrorT fits the bill, though it would probably be more
convenient to define your own version that maps only the error:
mapErrorTE :: (e1 -> e2) -> ErrorT e1 m a -> ErrorT e2 m a
Do you have an example where a more generic mapError would make sense?
More information about the Haskell-Cafe