Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Untagged union types.


My 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://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)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: