4 ms·
Languages that support algebraic data types have a much better solution. You can explicitly declare which types can occur and it can be "A or B". It's called AD
by waps 12y ago
Languages that support algebraic data types have a much better solution. You can explicitly declare which types can occur and it can be "A or B". It's called ADTs and it's the real solution to these problems.
http://en.wikipedia.org/wiki/Algebraic_data_type http://en.wikipedia.org/wiki/Algebraic_data_type
- masklinn 12y ago> Languages that support algebraic data types have a much better solution. Which I mentioned in my original comment… > You can explicitly declare which types can occur and it can be "A or B". It's called ADTs and it's the real solution to these problems. Well no actually, an ADT is a single type with multiple data-divergent constructors (although GADT may fit the bill, maybe with datakinds, I've yet to understand those). In `data List a = Nil | Cons a (List a)`, the only type is List. Which is why I specifically noted that a closed set was necessary for tagged unions. There are languages which safely[0] handle actual type unions (genuine type coproducts), they are much rarer than types supporting simple tagged unions. IIRC, /u/munificent did a post on that for his magpie language although I don't remember if he ever implemented it. David Pierce's Whiley also seems to use type unions[1] [0] an important discriminant, C has unions but they're not memory — let alone type — safe. [1] http://whiley.org/2013/07/31/understanding-why-union-types-are-useful/ http://whiley.org/2013/07/31/understanding-why-union-types-a...