Bind the other predecessors when matching on more than one number
developedby opened this issue · comments
Is your feature request related to a problem? Please describe.
If we do
switch x:
case 0:
case 1:
case _:
In the last case the variable x-2
is bound. However, x-1
is not and users must either do x - 1
or x-2 + 1
, which is counterintuitive.
I'd like to be able to write this fibonacci function
fib n = switch n { 0: 0; 1: 1; _: (+ (fib n-1) (fib n-1))
Describe the solution you'd like
We should bind the other predecessors using a use
term. In the fib example above, with should convert the code to this
fib = @n switch n {
0: 0
_: switch n-1 {
0: 1
_: @n-2 use n-1 = (+ n-2 1); (+ (fib n-1) (fib n-2))
}
}
Describe alternatives you've considered
Keeping things as they are would also work, just would be slightly more annoying for users in some cases.