4 ms·
The other one I want occassionally is "or". Imagine Left and Right contained data of compatible types, then I'd like to extract that data (regardless of tag) l
by andyferris 2y ago
The other one I want occassionally is "or".
Imagine Left and Right contained data of compatible types, then I'd like to extract that data (regardless of tag) like so:
if x is Left(y) or x is Right(y) then ...
That way I only need to write the `...` part once. (This could be combined with the rest of the pattern matching machinery in interesting ways, and would probably need to have eager matching / short-circuiting semantics in case both cases match).
- lptk 2y agoWe definitely want to get into that! Unfortunately it's not completely straightforward. A simple desugaring doesn't work due to our support for intermediate bindings and computations, which we don't want to recompute.
- HelloNurse 2y agoDo you mean something like compiling if (x is Left(Foo(y)) or x is Right(Foo(y))) and (y<5 or z>2) then 5 and destructuring Foo(y) only one time and dealing with parentheses?