3 ms·
I remember being told about this when I was introduced to type isomorphisms. Sum types correspond to addition, product types correspond to multiplication and fu
by reycharles 14y ago
I remember being told about this when I was introduced to type isomorphisms. Sum types correspond to addition, product types correspond to multiplication and function types correspond to exponentiation.
In haskell types:
* Either a b corresponds to a+b
* (a,b) corresponds to a*b
* a -> b corresponds to b^a
Update:
I forgot 0 and 1. I don't know what 0 would be in haskell. Think of 0 as a type that does not have a constructor. 1 is () (the unit type).
- tikhonj 14y agoYou can actually write an "empty" (ignoring ⊥) type: data Void Apart from maintaining symmetry and keeping the type system elegant, this is also very useful when you want to use types as "tags", ensuring they cannot be instantiated.