4 ms·
I find it very intuitive, but maybe it's because of a missing link or two. Boolean arithmetic sometimes uses + for OR and * for AND. When considering only zero
by rkallos 2y ago
I find it very intuitive, but maybe it's because of a missing link or two.
Boolean arithmetic sometimes uses + for OR and * for AND. When considering only zero and non-zero values, the semantics are the same. 1 + 1 + 0 is non-zero, 1 * 1 * 0 is zero. Substitute + for OR and * for AND, and you wind up with the "same" result.
From the linked article:
> one is „and data“, the other is „or data“.
Structs/records/product types fit the description of "and data", because it's a compound value comprised of this type AND that type AND that other type, etc.
Unions/sum types fit the description of "or data" because it's either this type OR that type OR that other type.
- gugagore 2y agoI don't think "type unions" correspond neatly to sums. When I think of a type union in mypy, typescript, Julia, etc, those languages have Union[int, int] as equal to int. But int + int is isomorphic to bool*int. The unions you're talking about necessarily require a notion of subtyping, I believe.