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

Ralf Hemmecke ralf at hemmecke.de
Sun Aug 19 17:08:44 EDT 2007


Hi Christian,

[...]

> 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. "has" is 
evaluated at runtime. If you call

   f(Fraction Integer)

then R = Fraction Integer

and (as I understand it)

   f(R: Ring): ...

simply means that whatever you plug in to f must (at least) be of 
category Ring. Inside the body of the function, the actual exports of 
the domain you plug in are taken. You didn't say

define R: Ring == Fraction Integer add;

[...I shortened that bit quite a bit...]

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

> In the above paragraph, I wanted to stress, that testing for anonymous 
> categories is dangerous.

> Consider testing for "with { /:(%,%)->% }" and not testing for Field. 
> That way, you cannot assume "/" really is a division function.

I completely agree here. It would be nice if there were any better means 
in Aldor to state axioms for functions than just creating a category 
(like AbelianMonoid).

Ralf



More information about the Aldor-l mailing list