chris-martin / bricks

Bricks is a lazy functional language based on Nix.
https://hackage.haskell.org/package/bricks
6 stars 1 forks source link

Allow dict patterns in let bindings #9

Open chris-martin opened 6 years ago

chris-martin commented 6 years ago

This seems rather equivalent to putting them in lambda parameters, and I don't think introduces any syntactic ambiguity, so I see no reason not to add this.

chris-martin commented 6 years ago

We should rename Param to Pattern while we're at it, and explain in the documentation that a single-variable binding is just a simple special case of a pattern.

chris-martin commented 6 years ago

Patterns would be strictly more general than the inherit style of let binding.

let { a, b, ... } = c; in d would be equivalent to let inherit (c) a b; in d

But these expressions have no direct analog in Nix:

chris-martin commented 6 years ago

I'm not sure now whether inherit should be allowed for let bindings. I'd like to remove it for simplicity. However, it does have an appealing symmetry with inherit in dict literals. So that also raises the question, then, of whether the dict version of inherit can also be obviated in some way. I don't see any good way to do that, though, without introducing a reliance on standard library functions for common use cases. At the moment I am inclined to keep let-inherit around, for the sake of the appealing symmetry.

chris-martin commented 6 years ago

On second thought, dict bindings that inherit from another dict could work just the same way.

bricks-repl> let x = { a = "1"; b = "2"; c = "3"; }; in { { a, b, ... } = x; }
{ a = "1"; b = "2"; }