3 ms·
The example in the polymorphism example feels strange to me. Why convert from Option to Result?
by timClicks 7y ago
The example in the polymorphism example feels strange to me. Why convert from Option to Result?
- zoul 7y agoIMHO conversions between various “error types” are quite common when gluing together different APIs. Like when you are chaining a handful of Result-returning calls and there’s one in the middle that returns errors using Option.
- coolsunglasses 7y agoThis is exactly right. We habitually lift `Maybe`/`Option` values into a more explicit and comprehensive `Either`/`Result` type in our programs. It's pretty common to have an error type hierarchy in the program too, so you could find yourself chaining from one `Either e` to another. There are libraries in Haskell and Rust for regularizing/code-gen'ing these patterns.