tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.24k stars 84 forks source link

Make record pattern matching recursive #1989

Open ajbt200128 opened 6 days ago

ajbt200128 commented 6 days ago

Is your feature request related to a problem? Please describe. I am currently working on the nix -> nickel transpiler PR over in this branch https://github.com/ajbt200128/nickel/tree/nix/nickel. One issue is that nix supports recursive pattern matching in record patterns:

let f = { x ? y, y ? x}: x + y; in f { x = 1; }
> 2

But nickel does not

let f = fun { x ? y, y ? x} => x + y in f { x = 1 }
  ┌─ <repl-input-0>:1:26
  │
1 │ let f = fun { x ? y, y ? x} => x + y in f { x = 1 }
  │                          ^ this identifier is unbound

Describe the solution you'd like It would be great if we emulated this behavior in nickel, as it make pattern matching more powerful, and would be more consistent since records can already be recursively defined in a normal definition. Additionally it will make the nix transpiler easier to write

Describe alternatives you've considered We could desugar this in only the transpiler, but that will require repeating a bunch of the pattern matching code that already exists in nickel