Proposal: add handleError to mtl

Edward Kmett ekmett at gmail.com
Wed Jun 5 19:50:01 CEST 2013


Sure. I can see merit to consistency with base in this regard. 

I would like a version of it in transformers monomorphized to the particular ErrorT monad though as well for consistency. Does that mean we'd want a liftHandle to avoid doing a lot of flipping with liftCatch?

I maintain mtl though, not transformers, so any action on adding it there would have to go through Ross.

Sent from my iPad

On Jun 4, 2013, at 11:04 PM, Erik de Castro Lopo <mle+hs at mega-nerd.com> wrote:

> Hi all,
> 
> I would like to propose the following convenience function (with
> implementation) for the mtl library:
> 
>    handleError :: MonadError e m => (e -> m a) -> m a -> m a
>    handleError = flip catchError
> 
> which follows the handle function from Control.Exception.Base:
> 
> 
>    handle :: Exception e => (e -> IO a) -> IO a -> IO a
> 
> Like the handle function, handleError allows the handling of
> exceptions to be expressed in a more natural way, turning:
> 
>    catchError
>        ( do
>             mumble
>             something
>             mumble
>        )
>        handler
> 
> into:
> 
>    handlerError handler $ do
>             mumble
>             something
>             mumble
> 
> 
> 
> -- 
> ----------------------------------------------------------------------
> Erik de Castro Lopo
> http://www.mega-nerd.com/
> 
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries



More information about the Libraries mailing list