Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC 0058] Named Ellipses #58

Closed
wants to merge 14 commits into from
35 changes: 35 additions & 0 deletions rfcs/0057-named-ellipses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
feature: Named Ellipses
start-date: 2019-11-14
author: deliciouslytyped
co-authors: none
shepherd-team: Eelco Dolstra, Michael Raskin, jD91mZM2
shepherd-leader: Michael Raskin
related-issues:
Named Ellipses - https://github.com/NixOS/nix/issues/2998
---

# Summary
[summary]: #summary

It should be possible to bind a name to ellipses in a function definition like `{ a, ...@extra }: null`, and `{ a, extra@... }: null`. This makes intuitive sense, and could remove the need for a lot of uses of `removeAttrs` that really just want to refer to the contents of ellipses.

Nixpkgs often gets commits like https://github.com/NixOS/nixpkgs/commit/a50653295df5e2565b4a6a316923f9e939f1945b with code that would be cleaner without the need for extra `removeAttrs`.

# Detailed design
[design]: #detailed-design
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to have an example of how people are currently using removeAttrs somehwere in the RFC, for comparison.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I meant. I'll add something when I have some spare brain for it, unless someone else wants to give it a shot.


The intent of this syntax is for `{...@args}:` to behave as consistent with `{...} @ args:`
as practical. As both `args @ {…}` and `{…} @ args` forms happen in Nixpkgs, both would be supported for named ellipses, too.

As `args @ {args}: ` is an error in Nix because of duplicate argument names, so should be `{extra, ...@extra}: `. As `(a @ { ... }: a) {a=1;}` returns `{a=1;}`, so should `({ a @ ... }: a) {a=1;}`. ```

TODO: consider what other languages like Haskell do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you want to consider pattern matching libraries, too, not just function arguments.

Some languages use notations that wouldn't fit well with the current use of ... in Nix: def f(a,b,*args): in Python, (lambda (a b &rest args) …) in Common Lisp.


# Drawbacks
[drawbacks]: #drawbacks
This increases the amount of syntax Nix has, thus creating some maintenance cost both for Nix itself, and for tools intended to work with Nix syntax (from highlighting to hnix)

# Alternatives
[alternatives]: #alternatives
Not doing this would not have any major impact besides not making Nix and nixpkgs nicer to use.