Suggestions regarding ? syntax and parameter order:
1. Make the most general concept primary
? naturally suggests optionality. Extending it to T ? E makes the general sum look like an extension of optionality, although algebraically the relationship goes the other way: an optional value is a sum with a singleton alternative.
The proposal already captures that relationship semantically but syntax is option-biased.
2. Give disjunction and optionality their own syntax
Both concepts seem important enough to deserve distinct notation:
E \/ T // general disjunction
T? // shorthand for Null \/ T
With the underlying constructor also ordered [E, T], this would align surface notation, existing higher-kinded inference, and ecosystem conventions without parameter reversal during desugaring or special inference rules.
Composition preserves different information
Separate syntax makes two distinct constructions clear:
-
(E \/ T)?: an optional choice : absent, left, or right.
-
E? \/ T?: a choice between optional payloads: left absent, left present, right absent, or right present.
The second preserves which branch was selected even when its payload is absent. These are different data models, and distinct syntax makes that difference explicit.
3. Consider a broader tagged-coproduct abstraction (generalize beyond error-handling)
Scala’s mindset was always revolving around building the coherent well-behaved foundations for the future to come, kind of more scientific philosophy, in contrast to other languages that aimed to solve specific corner-case issues in the ad-hoc but practical way which leans more towards engineering philosophy.
Optionality and Error handling are practical and can be important first class language features but the foundations backing them could be more generic.
For example, alternatives Dog, Mammal, and Animal overlap through subtyping.
A tagged sum should still distinguish a dog explicitly embedded in the first, second, or third alternative. The selected branch must survive construction and extraction independently of the payload’s runtime type.
A convenient generic coproduct abstraction (with constant runtime overhead) could be the fundamental basis for Options, Errors and possible other advances usecases.
P.S.:
posting from alt account because my main one was blocked from replies likely because I did several cycles of delete-edit-post of the same message.