infinisil changed the topic of #nix-lang to: Channel for discussing Nix as a language - https://nixos.org/nix/manual/#chap-writing-nix-expressions - Logs: https://logs.nix.samueldr.com/nix-lang/
<infinisil> Hmm, what if Nix had a set type
<infinisil> Okay so first, lists should use "," to separate elements
<infinisil> > someList = [ a, b, c ]
<{^_^}> error: syntax error, unexpected ',', at (string):369:16
<infinisil> And then we can easily also support sets
<infinisil> > someSet = { a, b, c }
<{^_^}> error: syntax error, unexpected ';', expecting ':' or '@', at (string):369:23
<infinisil> Not sure about the semantics yet though
<infinisil> For one, any orderable items should be insertable. Meaning you can put in ints and strings
<infinisil> You should be able to check for element existance in the set with `someSet ? c`
<infinisil> And you should be able to merge sets with `someSet // someOtherSet`
<infinisil> This also leads to integers being allowed in attribute sets, so you could `{ 1 = "foo"; 2 = "bar"; }`
<infinisil> Not being able to use integers in attribute sets is one thing that's annoyed me for a while
<infinisil> Also, you should be able to supply your own comparable types
<infinisil> So you could declare `{ __compare = self: other: ...; foo = "foo"; }` and use that in sets or as an attribute set name
<infinisil> Oh and of course, all string-coercible values should work too
<infinisil> A good reason for wanting sets is NixOS modules. Oftentimes lists are used to represent what are actually sets
<infinisil> E.g. environment.systemPackages, boot.blacklistedKernelModules, environment.extraOutputsToInstall, etc.
<infinisil> The fact that they're currently lists means that option merging is non-deterministic and that people can't remove entries again
<infinisil> Although, I'm actually not sure if sets could fix the latter..
<infinisil> Maybe `{ foo, bar }` should just be a shorthand for `{ foo = true; bar = true; }`
<infinisil> Hmm, or should it be `{ ${foo} = true; ${bar} = true; }`
<infinisil> `{ ${foo}, ${bar} }`
<infinisil> builtins.mergeAttrsWith builtins.add { x = 10; } { x = 20; }
<infinisil> builtins.intersectAttrsWith builtins.add { x = 10; } { x = 20; }
<infinisil> > mergeAttrsWith = op: a: b: a // lib.mapAttrs (n: bv: op a.${n} bv) (builtins.intersectAttrs a b)
<{^_^}> mergeAttrsWith defined
<infinisil> > :p mergeAttrsWith builtins.add { x = 10; y = 20; } { y = 30; z = 40; }
<{^_^}> { x = 10; y = 50; }
<infinisil> > mergeAttrsWith = op: a: b: a // b // lib.mapAttrs (n: bv: op a.${n} bv) (builtins.intersectAttrs a b)
<{^_^}> mergeAttrsWith defined
<infinisil> > :p mergeAttrsWith builtins.add { x = 10; y = 20; } { y = 30; z = 40; }
<{^_^}> { x = 10; y = 50; z = 40; }
<infinisil> > intersectAttrsWith = op: a: b: lib.mapAttrs (n: bv: op a.${n} bv) (builtins.intersectAttrs a b)
<{^_^}> intersectAttrsWith defined
<infinisil> > :p intersectAttrsWith builtins.add { x = 10; y = 20; } { y = 30; z = 40; }
<{^_^}> { y = 50; }
<infinisil> > mergeAttrsWith = op: a: b: a // b // intersectAttrsWith op a b
<{^_^}> mergeAttrsWith defined
<infinisil> > :p mergeAttrsWith builtins.add { x = 10; y = 20; } { y = 30; z = 40; }
<{^_^}> { x = 10; y = 50; z = 40; }
<infinisil> These should probably be nixpkgs functions anyways
ris has quit [Ping timeout: 256 seconds]
ddellacosta has quit [Ping timeout: 264 seconds]
puck has quit [Quit: nya]
puck has joined #nix-lang
mvnetbiz_99 has joined #nix-lang
__monty__ has joined #nix-lang
ris has joined #nix-lang
l33[m] has quit [Ping timeout: 260 seconds]
l33[m] has joined #nix-lang
kalbasit has joined #nix-lang
rajivr has quit [Quit: Connection closed for inactivity]
ddellacosta has joined #nix-lang
kalbasit has quit [Ping timeout: 240 seconds]
ddellacosta has quit [Ping timeout: 246 seconds]
rajivr has joined #nix-lang
__monty__ has quit [Quit: leaving]