3 ms·
How do they differ?
by brabel 9y ago
How do they differ?
- hermanhermitage 9y agoNomenclature varies, but I'm guessing the author of comment is using 'union' as the sum analog of tuples (unnamed fields) and 'sum' as the sum analog of struct/records (ie named fields).
- tel 9y agoThe Union of Int and Int is exactly Int; the Sum is not. The union of two types contains all values that are in either component type. The sum of them contains all of the values of the first type, each one associated with a tag like “I came from the left side” plus all of the elements from the second type with a similar tag. The Union of Bool and Bool has 2 values, the Sum has 4. If we define Maybe[A] to be the process of unioning on “null” to the values of A then Maybe[Maybe[A]] = Maybe[A]. If it’s defined with a Sum then that equation doesn’t hold.