[Aldor-l] define keyword
Manuel Bronstein
Manuel.Bronstein at sophia.inria.fr
Sun May 22 12:56:38 EDT 2005
> According to the Aldor User Guide, it is necessary to use the define
> keyword when defining Categories, for its functions to be visible. For
> example:
>
> #include "aldor"
> define CatA: Category == with {
> funcA: Integer -> Integer;
> }
>
>
> is considered necessary to see that CatA is of type Category AND has the
> funcA function. However, I did not come across a case, where the âdefineâ
> is really necessary.
>
> Is the previous example equivalent with
>
> #include "aldor"
> CatA: Category == with {
> funcA: Integer -> Integer;
> }
>
> , or is there any difference between these two versions of defining CatA?
>
There is a difference: in the aldor form Name:T == V
only the type 'T' of 'Name' is visible when you import Name in scope.
Its value 'V' is not visible. For example: MyInteger:Ring == add { ... }
when you 'import from MyInteger', only its type 'Ring' is known in scope,
not the details of the rhs (the add part). This design is not desirable
for categories. Indeed, if you say CatA:Category == with {...} and use
a variable 'MyType:CatA' then CatA is imported and all that is known about
it by the compiler is that it is of type 'Category'. Here you want the
compiler to also know about the value of CatA, namely the 'with {}' part
in the right-hand side. Adding the keyword 'define' to any declaration
causes the compiler to also import its value in scope. Thus,
a:Integer == 2 and 'define a:Integer == 2' are supposed to have
different effects in the compiler. This seems to be mostly relevant for
categories though.
Cheers,
-- mb
More information about the Aldor-l
mailing list