[Nix-dev] maximal sharing and comparisons.

Nicolas Pierron nicolas.b.pierron at gmail.com
Sun Nov 23 13:41:57 CET 2008


On Sun, Nov 23, 2008 at 13:32, Eelco Dolstra <e.dolstra at tudelft.nl> wrote:
> 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...

In this problem terms have the same content and the same position
information (in NixOS, they are supposed to be extracted from one
file), this is the reason why I was asking this question.  ATerm
allows to have pointer to pointer comparison in order to compare full
terms so this should be possible.

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron
- If you are doing something twice then you should try to do it once.



More information about the nix-dev mailing list