3 ms·
How do sum types make multiple return less useful? Multiple return is more like returning a single value of a product type—like a tuple or, less sexily, struct
by tomjakubowski 9y ago
How do sum types make multiple return less useful? Multiple return is more like returning a single value of a product type—like a tuple or, less sexily, struct—than like returning a single value of a sum type. What am I missing?
- TheDong 9y agoMultiple return is almost always used as an optional/either type construct. If you have a type for Some | None, then the return type of maps/chans/etc of (T, bool) aren't needed. Similarly, the (T, err) returns can be replaced by a T | error sum type. Sometimes multiple returns are used in other cases, but returning a struct covers those, or proper tuples where the value you return is a tuple. I'm just claiming that multiple return is 90% of the time being used to patch over the lack of proper optional or either types.