haskell / mtl

The Monad Transformer Library
http://www.haskell.org/haskellwiki/Monad_Transformers
Other
362 stars 63 forks source link

Add modifyError :: MonadError e' m => (e -> e') -> ExceptT e m a -> m a #82

Closed akrmn closed 2 years ago

akrmn commented 3 years ago

I recently came to this as a handy way to adapt a function from one MonadError to another. I couldn't find anything with this signature on hoogle, so I thought I'd add it here. I'm not 100% sure about the name, so any suggestions are welcome. I hope the docs are clear enough.

akrmn commented 3 years ago

hi @ekmett @hvr I'd really appreciate getting some feedback on this, who would be the right person for that? thanks!

ekmett commented 3 years ago

A couple of thoughts:

I have no real objection to adding something with this functionality.

However, the name doesn’t quite follow mtl/transformer conventions where lifts are used in a stylized manner to raise operations from lower monads in the stack (and are supplied by transformers rather than mtl).

akrmn commented 3 years ago

I have no real objection to adding something with this functionality.

thanks!

However, the name doesn’t quite follow mtl/transformer conventions where lifts are used in a stylized manner to raise operations from lower monads in the stack (and are supplied by transformers rather than mtl).

I think this would have to be defined in mtl, though, since the type has to mention MonadError, which is defined here. Regarding the name, I absolutely agree, naming things is hard indeed. Perhaps

I really don't have a strong opinion regarding the name, so I'll be happy to have any other suggestions

emilypi commented 3 years ago

@akrmn I like this functionality. Can I suggest modifyError or translateError (or some variation thereof)? Then you have the intuition withError = modifyError (f :: e -> e).

chessai commented 3 years ago

Can this be renamed to modifyError? Naming is really the only thing keeping it unmerged.

akrmn commented 3 years ago

@emilypi @chessai thanks for the suggestion, I'll rename it to modifyError.

emilypi commented 2 years ago

Needs a resolution and a changelog entry and we're good

akrmn commented 2 years ago

hey @emilypi thanks for taking this forward

akrmn commented 2 years ago

I've just added the changelog entry, sorry I forgot to do it earlier

emilypi commented 2 years ago

Thanks for bearing with us @akrmn and thanks for the PR :)