nickel
nickel copied to clipboard
Could the last argument of `switch` be curried?
Is your feature request related to a problem? Please describe.
Because of how large the expression can get, I end up moving switch statements to their own functions, as such:
let see = fun color => switch {
Red => "I see Red",
Green => "I see Green",
Blue => "I see Blue",
} color
in
see `Red
As you can see, the dance to pass the color parameter feels very unnecessary, but the parser fails without it.
Describe the solution you'd like
It would be nice to be able to write switch { A => .. , B => .. } and get a function of type <A , B> -> Dyn
The default block should be able to fit as well: switch { A => .. , _ => .. } would be of type forall e. <A | e> -> Dyn
The fact that switch takes the argument last is a bit unfortunate. I don't know yet if we will keep the syntax this way. However, if we do, I guess the currification doesn't hurt.
If we reverse it to something like case foo of {...} or match foo with {...}, then there are other possible solutions to this problem, such as Haskell's lambda case or OCaml syntax let f = function Foo -> 1 | Bar -> 2. The idea is fundamentally to have a special syntax that squashes a function definition of one argument witch pattern matching.
As of 0.3.0, this is how match works, so I think we can close this issue.