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

WIP: Add scoped expressions inspired by OCaml #12471

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KoviRobi
Copy link

@KoviRobi KoviRobi commented Feb 14, 2025

TODO: The parsing works but it has the semantics of normal with currently.

I am currently calling it scoped dot, because calling it innermost with would maybe make people confuse them with the current outermost with expressions

Also put up a discussion at https://discourse.nixos.org/t/alternatives-to-with-expression/60272

This solution took inspiration from OCaml: "module access notation" in https://ocaml.org/docs/modules and "local open" in https://ocaml.org/manual/5.3/moduleexamples.html.

Motivation

With expressions are convenient, but confusing (i.e. taking the outermost binding), but the alternative of using builtins.attrValues { inherit (foo) a b c; } instead of with foo; [a b c] is cumbersome.

This is taking inspiration from OCaml.

Context

Changing the parser is always something to be done with care. I should definitely add more tests, and people should try it out before it gets merged with something suboptimal.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

The parsing works but it has the semantics of normal `with` currently.

I am currently calling it `scoped dot`, because calling it `innermost
with` would maybe make people confuse them with the current `outermost
with` expressions
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Feb 14, 2025
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/alternatives-to-with-expression/60272/1

@KoviRobi
Copy link
Author

Oh wait there's https://github.com/r-burns/nixos-rfcs/blob/rfc-inherit-as-list/rfcs/0110-inherit-as-list.md that I need to read over the weekend

enum class Binding {
/** Classic `with` behaviour */
Outermost,
/** `with` behaviour mimicking OCaml's `foo.( <expr> )` */
Copy link
Member

Choose a reason for hiding this comment

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

mimicking

In what ways does it fall short?

@@ -0,0 +1 @@
"x: (as-a as-b) y: (bs-a bs-b)"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"x: (as-a as-b) y: (bs-a bs-b)"
"x is (as-a as-b) and y is (bs-a bs-b)"

Confused me for a sec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants