[Aldor-l] "has" and "with" and bug
Christian Aistleitner
tmgisi at gmx.at
Mon Aug 20 04:51:04 EDT 2007
Hello,
>> To me, the "has" keyword provides a possibility to check a domain's (in
>> contrast to an identifiers) type.
>>
>> But let us assume, I am wrong, and what you describe is a bug. "has" can
>> only be used to check the type of an identifier. "has" cannot check the
>> domain, the identifier refers to.
>> Consider the following piece of code.
>>
>> f( R: Ring ): () == {
>> if R has Field then
>> {
>> --do something
>> } else {
>> --do something else
>> }
>> }
>> f( Fraction Integer );
>>
>> Within the function call to f, "R" is an identifier referring to a
>> domain--just as we had in the above piece of code.
>> The identifier "R" is of type Ring. Now "has" within f's body can only
>> check the type of the identifier--not of the domain the identifier
>> refers to. So especially "R has Field" has to by false regardless of the
>> value of "R", as "R"'s type is Ring and cannot satisfy Field.
>>
>> Assuming, I am wrong, and what you describe is a bug, the "correct"
>> behaviour of "has" would turn it rather ... useless.
>
> Well, in your code, R appears as a parameter to a function.
Yes. But in both cases (the above code, and the code presented in earlier
mails of this thread), we have a constant identifier referring to a
domain. To me, it is quite the same situation.
> "has" is evaluated at runtime.
Yes.
> If you call
>
> f(Fraction Integer)
>
> then R = Fraction Integer
More precisely, we know that
R: Ring == Fraction Integer.
So,
R: Ring == some_right-hand_side
. And that is indeed of the same shape as we had in the previous code
Dom: with {} == some_right-hand_side
.
> and (as I understand it)
>
> f(R: Ring): ...
>
> simply means that whatever you plug in to f must (at least) be of
> category Ring.
Yes. Same for
Dom: with {} == some_right-hand_side
. There again "some_right-hand_side" has to be _at least_ (as opposed to
"exactly" or "trimmed down to") of type "with {}".
> Inside the body of the function, the actual exports of
> the domain you plug in are taken.
No. Consider the following counter example:
#include "algebra"
f( R: Ring ):() == {
import from R;
1 / 1;
}
f( Fraction Integer );
fails to compile with
"demo.as", line 4: 1 / 1;
....^
[L4 C5] #1 (Error) There are no suitable meanings for the operator `/'.
. However, replacing "R: Ring" by "R: Field" compiles and works:
#include "algebra"
f( R: Field ):() == {
import from R;
1 / 1;
}
f( Fraction Integer );
In both cases, "the actual exports of the domain you plug in" are the
same. However, the first piece of code does not work.
>>> That is the same exports as for Foo.
>>> Still, main() prints "T".
>
>> Yes, because still a function "privateFunc" can be found. That's ok for
>> me.
>
> It boils down to the question whether after
>
> macro DomA == add {privatfunc():()=={}}
> DomB: with {} == DomA;
>
> DomA and DomB are two different things.
>
> In my eyes they are. Maybe in your eyes they are different, too.
Yes. In my eyes they are different too.
> But I want to hide (for "has") that DomB has any knowledge of
> "privatfunc" and you don't.
>
> If you allow "has" to see "privatefunc", that violates the data
> hiding principle.
No, it does not.
And it now seems to me that we have been following different goals. The
discussion does not seem to be about static and dynamic types, but telling
Aldor to not export a function giving in the "add" part ;)
(However, I did not erase my above comments, as we do not seem to have the
same view on typing in Aldor, and it may be interesting in straightening
things out there.)
You can tell Aldor to _not_ export a function by adding "local" to the
definition of the function.
Consider the following piece of code:
#include "aldor"
import from String, TextWriter, Character;
Dom: with {
} == add {
ExportedFunc(): () == {}
local UnexportedFunc(): () == {}
}
main(): () == {
stdout << "Dom has 'ExportedFunc' ? " <<
(Dom has with {ExportedFunc: ()->()}) <<
newline;
stdout << "Dom has 'UnexportedFunc' ? " <<
(Dom has with {UnexportedFunc: ()->()}) <<
newline;
}
main();
and its output:
Dom has 'ExportedFunc' ? T
Dom has 'UnexportedFunc' ? F
.
Kind regards,
Christian
More information about the Aldor-l
mailing list