Translate pattern matching into method calls (these methods form a zero-plus monad), similar in spirit to how for-comprehensions are compiled.
For each case, express all patterns as extractor calls, guards as 0-ary extractors, and sequence them using flatMap
(lifting the body of the case into the monad using one).
Cases are combined into a pattern match using the orElse combinator (the implicit failure case is expressed using the monad's zero).
TODO:
interaction with CPS
Array patterns
implement spec more closely (see TODO's)
DCE
use manifests for type testing
(longer-term) TODO:
user-defined unapplyProd
recover GADT typing by locally inserting implicit witnesses to type equalities derived from the current case, and considering these witnesses during subtyping (?)
recover exhaustivity and unreachability checking using a variation on the type-safe builder pattern
Interface with user-defined match monad?
if there's a match in scope, we use this as the match strategy, assuming it conforms to MatchStrategy as defined below:
traitMatchOptimizations extends CommonSubconditionElimination with DeadCodeElimination with SwitchEmission with OptimizedCodegen
Translate pattern matching into method calls (these methods form a zero-plus monad), similar in spirit to how for-comprehensions are compiled.
For each case, express all patterns as extractor calls, guards as 0-ary extractors, and sequence them using
flatMap
(lifting the body of the case into the monad usingone
).Cases are combined into a pattern match using the
orElse
combinator (the implicit failure case is expressed using the monad'szero
).TODO:
(longer-term) TODO: