2 ms·
No, you cannot. var foo: (T | None) | None = None Which None do you mean here? This is just basic logic: (X or Y) or Y <=> X or Y Untagged unions cannot mod
by islon 4y ago
No, you cannot.
var foo: (T | None) | None = None
Which None do you mean here?
This is just basic logic: (X or Y) or Y <=> X or Y
Untagged unions cannot model that. Contrast it with tagged unions:
var foo: Option<Option<T>> = Some(None)
var bar: Option<Option<T>> = None
Now you can reason about where the None means.
- kaba0 4y agoI may have not been clear, but that “flattening” is what I meant, and mentioned it as a “feature” (when Some(None) and None is equally useful/useless). Surely, if you want to distinguish between 3 states you need more data, hence my recommendation of Option<T?>