4 ms·
> To stuff all possible failures into the `Left` case of `Either` you have to wrap all possible failure types into a sum type, possibly with multiple layers of
by ParetoOptimal 2y ago
> To stuff all possible failures into the `Left` case of `Either` you have to wrap all possible failure types into a sum type, possibly with multiple layers of nesting (huge PITA).
Is this not inherent complexity? Is there some language or approach you believe makes this easier? Does it provide the same or similar correctness?
- ackfoobar 2y agoUntagged union types.
- ackfoobar 2y agoMy previous answer was too short. Here is some more elaboration: I said "untagged union" to distinguish it from "tagged union", which is another name for sum types. There are several comments that incorrectly called sum types "union types". But it isn't tagging that's the problem, it's the limitation that a value can only be of one type in vanilla HM. And indeed both OCaml and Haskell go beyond vanilla HM: https://ocaml.org/manual/5.2/objectexamples.html https://ocaml.org/manual/5.2/objectexamples.html https://hackage.haskell.org/package/vary-0.1.0.3 https://hackage.haskell.org/package/vary-0.1.0.3 BTW `thumbnailService :: String -> VEither [ServerUnreachable, IncorrectUrl, NotAnImage, TooBigImage] Image` is isomorphic to `Image thumbnailService(String url) throws ServerUnreachable, IncorrectUrl, NotAnImage, TooBigImage`. And nobody likes checked exceptions in Java. (hyperbole)