[Nix-dev] maximal sharing and comparisons.

Nicolas Pierron nicolas.b.pierron at gmail.com
Sun Nov 30 00:17:36 CET 2008


On Sun, Nov 23, 2008 at 16:23, Marc Weber <marco-oweber at gmx.de> wrote:
> You're all right, we have to think about what equality means here.
>
> The most sensible thing would be:
>
>  1)
>  7 == (_plus 6 1) is equal
>
> the same way
>  2)
>
>  let f = __trace "foo" (_plus 6 1)
>  in f == f
> is without printing "foo"..
>
> So if the terms are the same we don't have to evaluate them. But if they
> are not we have to evaluate them to make a final decision because the 7
> = 6+1 example should hold.

So, the evaluation of the following expression:

(__trace "bad" (__trace "good" 1)) == (__trace "bad" 1)

should only print "good" and not "bad".  If we admit the previous
example to be correct, how should we consider this one:

let
  tkFirst = f: s: __trace "bad tkFirst" f; /* ignore s */
in
  (tkFirst (__trace "good" 1) (__trace "bad args" 0)) == (tkFirst 1 0)

which fit the definition of laziness and where both bad trace call
does not have to be evaluated to get the result.  In this example the
"bad args" should never be evaluated because it is never used.

These examples show us that the function arguments have to be strictly
equal (at least in user defined function call) otherwise we have to
substitute arguments inside the function call.

-- 
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