Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.
Is something like this possible in Haskell today with a library?
doSomething :: MonadError '[FooError, BarError] m => m ()
doSomething = do
doFoo -- can throw FooError
doBar -- can throw BarError
Came across this: https://old.reddit.com/r/haskell/comments/8ugf4o/on_eithert_perpetually_curious/
But nothing concrete in the comments section, unfortunately.
There is https://int-index.com/ether/ though
But it doesn't work in GHC 8.8.
Wild question: would this no longer be a problem if I switch to polysemy?
This looks like multiple error types will work http://hackage.haskell.org/package/polysemy-220.127.116.11/docs/Polysemy-Error.html
Yes, polysemy's Error effect allows dealing with each error separately. I haven't found a solution that I like in mtl. There is classy errors, as Matt Parsons refers to here: https://www.parsonsmatt.org/2018/11/03/trouble_with_typed_errors.html where your type signatures end up looking like this:
doSomething :: (MonadError e m, AsFooError e, AsBarError e) => m ()
doSomething = do
doFoo -- can use `throwing _FooError`
doBar -- can use `throwing _BarError`
But as he mentions in that post, this only allows you to compose your errors, it doesn't make it easy to catch them in different places. I think you can catch them, but you can't show that you've caught them in the type signature. He's gone on to write https://hackage.haskell.org/package/plucky which is aimed at solving this problem.
Problem with mtl are it's fundeps - in polysemy we instead use plugin which when fails to infer member constraint let's user fill in concrete error types manually
I posted this in reddit, and some suggested: https://functor.tokyo/blog/2019-07-11-announcing-world-peace
Discussion of that 'friendly' library here: https://old.reddit.com/r/haskell/comments/cbsh8o/ann_worldpeace1000_a_library_providing_open_sum/
As well as discussion of open union types (that's the keyword I should have used in Google for this problem) here: https://old.reddit.com/r/haskell/comments/5jc9mt/control_flow_with_an_open_sum_type/