On Mon, Jun 15, 2015, at 11:52 PM, Matt Williams wrote:
When we have a type, T, with constructors A and B
(e.g. data T = A x y z | B x y)
How do I understand the relationship between A, B and T? I had thought I could use the sub-class relationship, but that doesn't seem to be true.
You are correct that A and B are not types in Haskell.
The relationship is that there are two different ways to construct a value of type T. Whenever a T is needed, you can use either A or B. That means, on the other hand, that whenever a T is consumed, you have to handle two cases: A and B.
Lastly, as a bit of a digression, you could imagine an alternate language in which A and B are subtypes of T, such that constructor A returns a value of type A, and constructor B returns a value of type B. I'm not an expert on the theory behind all of this, but I know that doing type inference would be much harder in such a language.
-Karl