3 ms·
Sum type comes from the fact that the resulting type has as many possible values as the types it is combining, summed. This is in contrast to product types like
by kazagistar 9y ago
Sum type comes from the fact that the resulting type has as many possible values as the types it is combining, summed. This is in contrast to product types like tuples and structs.
Either<u8, bool>
This has exactly 256 + 2 possible values.
Tuple<u8, bool>
This has exactly 256 * 2 possible values.
Of course, this simple numerical interpretation breaks down as soon as you have something like a linked list which has infinite possible values, but even then, you can fuzz the rules a bit and get useful information out of the math. But that is the core intuition.