3 ms·
Assuming non-fixed width integers, how can you have an infinite sum type?
by smabie 7y ago
Assuming non-fixed width integers, how can you have an infinite sum type?
- tel 7y agoThere’s nothing wrong with an infinite sum, in principle. You can’t usually define them unless you can use recursion. In the case of integers you can do data Int = Positive Nat | Negative Nat data Nat = Zero | Succ Nat
- arianvanp 7y agoYou can't. The Natural number definition combines a sum type with a recursive position. Or in other words, a finite tag (either zero or successors, 2 options) plus a pointer to the next value in the case of successor.