Gabriella439 / Haskell-Pipes-Safe-Library

Safety for the pipes ecosystem
BSD 3-Clause "New" or "Revised" License
26 stars 21 forks source link

Add new functions: tryP and catchP #24

Closed jwiegley closed 9 years ago

jwiegley commented 9 years ago

These allow for more direct handling of exceptions raised in Proxies, similar to tryC and catchC found in conduit. I'm not sure the MonadSafe constraint is even necessary, it work fine with just MonadCatch, but I have a feeling you would have a deeper insight into this, @Gabriel439.

Gabriella439 commented 9 years ago

The main Proxy type implements MonadError and the catchError method for that is the same as the catchP you wrote.

I also think try could be written in terms of catchError in a way that is Proxy-independent:

try :: MonadError e m => m a -> m (Either e a)
try m = fmap Right m `catchError` (\e -> return (Left e))
jwiegley commented 9 years ago

Ah, excellent, I like that solution much more.