-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement pattern matching in parser #49
Comments
A long term goal is to have incomplete pattern matching sections compile to a refinement check |
As agreed in gitter dm, also pattern matching on all these: main = \input -> case input of
(a, (b, c)) -> foo a b c
"string" -> bar
[a, b, c] -> foo a b c
2 -> bar
[(a,b), c, 2] -> foo' a b c Just leaving this here for record keeping. |
case patternn of
(a,a) -> match1Out matches like the above aren't allowed (i.e. can't have multiple of the same variable in a match) |
checkout "_" (i.e. ignore) pattern matching |
let myConst = (left MyInt0) 8
in case myConst of
((left MyInt0) 8) -> ("Success!", 1)
x -> ("default case", 0) This breaks becuase |
note that #71 should help with pattern matching on smart constructors and other functions |
Let's take the simplest pattern matching case, with no variables first:
this is equivalent to
|
Let's add in a variable:
Then we can do something like
|
How about these cases?: let a = 0
in case a of
(x,y) -> 0
_ -> 1 let a = (0,0)
in case a of
(x,y) -> 0
_ -> 1 knowing that:
|
This seems like it works for implementing your second case, and you can just do the inverse for case 1 |
The first part of this should be pretty easy: all we need to do is be able to match on pairs and zero.
The second part is matching user-defined types and is blocked by #47
The text was updated successfully, but these errors were encountered: