Mikaela, Lily, Violet, and Ciri — a plural collective of nerdy, quoiromantic, poly, lesbian computer engineers and leftists.

Current media obsessions: Persona 5, RWBY, Cosmere


leftpaddotpy
@leftpaddotpy

You may know about the following completely normal behaviour in javascript from the excellent talk by Gary Bernhardt entitled "wat":

js> {} + []
0
js> {} - []
-0
js> [] - {}
NaN
js> [] + {}
"[object Object]" 

Enough about languages that are definitely not haskell[1], let's talk about nix

» nix repl
Welcome to Nix 2.11.0. Type :? for help.

nix-repl> f = a: a

As we know, we can define functions. A slightly less known fact is that they are not equal to each other, but that is generally a reasonable idea because meaningful function equality is undecidable in general:

nix-repl> f == f
false

You can also define attribute sets:

nix-repl> s = { x = 1; }

nix-repl> s == s
true

Equality on attribute sets is value based, based on the values of the attributes:

nix-repl> s' = { x = 1; }

nix-repl> s == s'
true

As we can clearly see, the equality depends on the equality of the attributes themselves and not their identity:

nix-repl> s2 = { check = f; }

nix-repl> s2 == s2
true

nix-repl> s3 = { check = f; }

nix-repl> s2 == s3
true

wat.


This "feature" is "will remove eventually" as of 2010 and is depended on by the nixpkgs initialization code since it compares lib.types.* values containing check lambdas. I somehow don't think "eventually" is happening very soon.

This poast brought to you by @puckipedia.

[1] actual haskell content may vary. conditions apply.


You must log in to comment.

in reply to @leftpaddotpy's post:

nope, if you look at the code linked above, it's a special case where the pointers are equal, which I'm not sure why that's not getting hit by f == f, but attribute sets aren't special; they're just comparing each attribute is the same.

well, except for if attribute sets include an outPath attribute, signifying being a derivation. then only that attribute is compared (cursed).

For what it's worth, you can define a functional equality which is "okay", which is equality of alpha-beta-normal forms (which is what Dhall uses for judgmental equality). It's not extensional equality, but it's still useful