top | item 34707025

(no title)

islon | 3 years 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.

discuss

order

kaba0|3 years ago

I 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?>