[Aldor-l] "has" and "with" and bug

Ralf Hemmecke ralf at hemmecke.de
Thu Aug 16 04:58:45 EDT 2007


Thank you, Christian, for taking your time to shorten the "problematic" 
code.

> What you experienced in your code is not related to "add", "with" or 
> function calls passing strange values, but is related to the inner 
> workings of the "has" construct.
> 
> Just take a look at this code:
> 
>   #include "aldor"
> 
>   import from String, TextWriter, Character;
> 
>   Dom: with {
>   } == add {
>      privateFunc(): () == {}
>   }
> 
>   main(): () == {
>      stdout << "Dom has 'privateFunc' ? " <<
>        (Dom has with {privateFunc: ()->()}) <<
>         newline;
>   }
>   main();
> 
> 
> Here goes the output:
> ____________________________________________
> caistlei at ibis
> cwd: /scratch/caistlei/ralf_type_context
> $ aldor -Fx -laldor demo.as && ./demo
> Dom has 'privateFunc' ? T

> I am sure you'd have expected to see "F" instead of the "T".

You very much guessed right.

> "has" checks whether or not a domain can satisfy the type you give. In 
> the above example "the domain" is the whole "add" expression. This 
> includes "privateFunc".

Oh, sorry, here I disagree. Your code says

   Dom has with {privateFunc: ()->()}

and not

   add {privateFunc(): () == {}} has with {privateFunc: ()->()}

. The first should give F, the second T.

> This observation relates nicely to the type of the domain. The type of 
> the add expression is
> 
>   with {
>     privateFunc: () -> ();
>   }
> 
> . However, this is not the type of "Dom". The type of "Dom" is
> 
>   with {
>   }
> 
> . That's what relates to
> 
>> AUG Chp. 7.8:
>>
>>    The type of the expression A add B is C with { x1: T1; ...; xn: Tn }
>>    where C is the type of A, and x1,...,xn are the symbols defined
>>    (using ==) in B, whose types are T1,...,Tn, respectively.

> But only because "Dom" hides "privateFunc" does not mean that it's 
> stripped off completely. The "has" function allows to check whether or 
> not "privateFunc" can be found withing the domain.
> "has" does not allow you to check whether or not it is in "Dom".

Again, I disagree. In

   Dom has with {privateFunc: ()->()}

the "add" part is missing, so "A add B" matches A with Dom and the type 
of Dom is "with {}"

To make that more clear replace your line

     (Dom has with {privateFunc: ()->()}) <<

with

     ((Dom add {}) has with {privateFunc: ()->()}) <<

OK, the compiler is unable to compile that. Why???

woodpecker:~/scratch>aldor -grun -laldor aaa.as
"aaa.as", line 11:         ((Dom add {}) has with {privateFunc: ()->()}) <<
                    ..............^
[L11 C15] #1 (Error) The domain is missing some exports.


So let's replace your line by

     (Foo has with {privateFunc: ()->()}) <<

and add another definition:

Foo: with {} == Dom add;

at the top of the file.

According to the quote above, we now truely have that the type of

   Dom add {}

is

   with {}

right? Or mor exactly

   (with {}) with {}

in order to match the pattern C with { x1: T1; ...; xn: Tn } from the quote.

That is the same exports as for Foo.
Still, main() prints "T". I hope, that you now agree, that this is a bug.

> The problem with your code is that you use "has" to check for the 
> presence of a function with an anonymous category. The function is 
> present (althoug invisible), hence the anonymous category can be 
> fulfilled, therefore you obtain "T".
> I'd suggest to use named categories instead.

That cannot have to do anything with named or unnamed categories. If I 
define

Bar: with { ... } == add {...}

then any test against a named category will fail. That would be pretty 
useless.

Ralf



More information about the Aldor-l mailing list