3 ms·
Proper sum types aren't enough to replace exceptions. Imagine every IO action having its own error type in a sum type. How do you compose them? Composing the
by Peaker 12y ago
Proper sum types aren't enough to replace exceptions.
Imagine every IO action having its own error type in a sum type. How do you compose them?
Composing the different error types wouldn't unify.
The best attempt I've seen in Haskell is the control-monad-exception[1] library, but I'm not sure how well that would interact with everything.
[1] https://hackage.haskell.org/package/control-monad-exception https://hackage.haskell.org/package/control-monad-exception
- adrusi 12y agoCheck out how rust handles error composition using its Result type
- danidiaz 12y ago> Imagine every IO action having its own error type in a sum type. How do you compose them? Perhaps by converting each error type to a common sum type. Something like "Either (Either error1 error2) result". Typeclasses like "Bifunctor" are quite useful for massaging the errors around: http://hackage.haskell.org/package/bifunctors-4.2/docs/Data-Bifunctor.html http://hackage.haskell.org/package/bifunctors-4.2/docs/Data-... Asynchronous exceptions do pose a problem for this approach though, as they can pop up in any function at any time. And perhaps a fully sum-type-based approach would clutter function signatures too much anyway.