3 ms·
Could you expand on the difference? I heard those two terms used interchangeably. edit: saw union/intersection types mentioned in another comment - I guess tha
by uryga 9y ago
Could you expand on the difference? I heard those two terms used interchangeably.
edit: saw union/intersection types mentioned in another comment - I guess that's what you were referring to?
- kccqzy 9y agoYes. Sum types are essentially discriminated unions. Given a value of a sum type, it is possible to tell which alternative it is. This is commonly done through pattern matching. Union types are a bit like C's undiscriminated unions in that you cannot tell what the actual type is. This makes them significantly less useful, and thus very few functional languages have them. Essentially when you get back a union type of A | B, you can only perform actions that make sense on both of them. This essentially means functions with a type variable (parametrically polymorphic) in typical functional languages. If we additionally have subtyping (which ML-like languages don't) this can be more useful. Side note: things like the `typeof` operator in JavaScript is muddling the water a bit. But I'm talking about the theoretical perspective.