[Nix-dev] maximal sharing and comparisons.

Eelco Dolstra e.dolstra at tudelft.nl
Sun Nov 23 13:32:16 CET 2008


Hi,

Nicolas Pierron wrote:

> I have a problem with the NixOS implementation.  I have remarked the
> following problem:
> 
> let
>   v = {foo=true;bar=false;};
>   a = builtins.trace v v;
>   b = a;
> in
>   assert a == b; true
> 
> where "v" is printed.  "v" should not be printed because unprocessed
> values of "a" and "b" are identical.

The `==' operator evaluates both terms to weak head normal form.  There is no
realistic way that it could see that "a" and "b" are the same without evaluating.

Also, `==' doesn't work on lists and attribute sets (not to mention functions)
because the list elements / attributes are not evaluated to normal form.  So `{a
= "foo" + "bar";} == {a = "foobar";}' will evaluate to false.  In fact, even `{a
= "foobar";} == {a = "foobar";}' evaluates to false because of the position
information in the attributes.  The evaluator should really print an error when
trying to compare lists and attribute sets...

See also this issue: http://bugs.strategoxt.org/browse/NIX-62

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list