Match with wildcard operator
Closed this issue · 1 comments
TimotejFasiang commented
Wildcard _
operator can be used with the switch
statement, it should also be usable with the match
statement
Ex:
def isList(input):
match input:
case List/Cons:
return "list"
case List/Nil:
return "empty list"
case _:
return "not list"
developedby commented
You can use _
or any other variable name as a wildcard in matches.
type MyMap:
Full { val, ~lft, ~rgt }
Empty { ~lft, ~rgt }
Leaf
def foo(map):
match map:
case MyMap/Leaf:
...
case m:
...
Here case m
matches both the Full
and the Empty
cases.
However, I think you're misunderstanding what match
does. It does not match on multiple possible types and we will not change it to do so.
With the way that we internally represent constructors and pattern matching it is impossible to do so. We could chage it to make that possible, but that would incentivize users to make really hard to understand programs, so we won't.