Pattern guards for functions and switch statements #830
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "ghallak/232"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes: #232
Created by: radrow
I'd elaborate a little bit on that. Note that many smart contract devs aren't familiar with functional programming. Also, mention that these expressions cannot be stateful
Created by: hanssv
Looks good from a quick look, are there any (actually running) tests over in
aeternity
repo?Created by: radrow
For the user facing syntax I think it would be better to have just one variant for simplicity. If there are no guards, then the expr could be
true
which can be optimized out later on. Also, I would rather opt for comma separated multiple guards -- this would ease implementing assigning values in guards like you can do in Haskell (but that's for another task). Then, no guards would be just an empty list here. @UlfNorell what do you think?Created by: radrow
Remove stateful context so there are no surprises
Created by: radrow
Add some negative test maybe?
Created by: UlfNorell
Not introducing redundant forms in the AST is good, and comma separated guards make sense. Especially if we want to add support for what is called pattern guards in Haskell land later. (What you have here is referred to as just guards.)
Done here 756c05c60038d774ce1156c7b65896ea9741036eHad to change this in 6b9bbfa in order to get a more relevant error message, and I've added a failing test for stateful guards as well.Let me know if you think this makes it clearer 2deb568be3081db48f2ea0ddf77337aa1bde88ba
Created by: radrow
Created by: radrow
So we may add assign-guards later on here
Created by: radrow
Created by: radrow
Might be also good to make
guard/0
a separate parserCreated by: radrow
Isn't there some combinator for optional parsing?
Created by: radrow
Review: Commented
You can compile a list of guards as a big conjunction.
Created by: radrow
I'd split the sentence before "if" and "otherwise". Otherwise good
Created by: radrow
why list of expr?
multiple guards, each guard corresponds to one body.
multiple guards, each guard corresponds to one body.
Created by: radrow
I don't get it, how do you represent
?
Created by: radrow
Or if it is invalid
The above does is not valid since the guard should be a single expr, so if you write
a > 0 && b > 0
instead ofa > 0, b > 0
in the first example it would be parsed like this:Notice that there are 2 guards and 2 bodies.
Do you think there's something wrong with that?
Done that here 70af4828483be4a8ac93a9b123411e2e0b946fef
Why do you think that guards should have comma separated exprs? Isn't it better if a single expr is used and boolean operators are used when needed?
If there are multiple guards and a single body, how would you parse something like
Created by: radrow
Uh, when talking about multiple guards we were talking about
| a > 0, b > 0
, so in the future we might have| a > 0, b > 0, let x = a + b, x > 10
. That's why there would be a list of guards.Multiple guard alternatives for a single pattern are great too, but then why not pack them into a list of tuples? They are conceptually together, so imo they should stay side by side.
My idea for the typing:
This way this:
can be expressed as (simplified for readability)
Created by: radrow
Because later we might want to add support for introducing variables in guards. Just like in Haskell you can do
There are tests here now (and they're passing):
4683da5b50
Created by: hanssv
This example won't compile 😛
Created by: hanssv
I'm not entirely convinced the new test is better 🤔
Now it does 91002c1f77fc164484f05c1ab82708805c5f35bb
Created by: hanssv
👍
In this commit e828099bd97dffe11438f2e48f3a92ce3641e85b I have disabled multiple tests that are related to aevm, including this one.
To make these tests work, changes are required to be made to icode generation which is deprecated as I understood.
Should I make these changes to icode generation? or is there another way to re-enable these tests?
Created by: hanssv
Ah, I had forgotten these tests were AEVM only... What makes them fail? I don't think we should just break AEVM compilation we should rather remove it properly then?
I have changed the icode generation so that aevm compilation won't break when no guards are used, but it will break when guards are used here 96dc007f00c37368b3c5603d04ab64244e9d70ac.
And I have reverted the commit that disables the aevm tests here 1525e80992f562dedfaacc61e61486291ef51675.
Created by: hanssv
Great!
Created by: hanssv
Review: Approved
Created by: radrow
Review: Approved
Merged by: ghallak at 2021-10-20 08:04:01 UTC