[Aldor-l] Using Aldor or SPAD

Ralf Hemmecke ralf at hemmecke.de
Sun Aug 20 04:01:49 EDT 2006


> | Currently, in aldor-combinat I am going to define something like...
> | 
> | define CombinatorialSpecies(L: LabelType): Category == with {
> |          <<exports: CombinatorialSpecies>>
> | }
> | CharacteristicSpecies(n:Integer)(L:LabelType): CombinatorialSpecies L == 
> | add {
> |          Rep == Set L;
> |          import from Rep;
> |          <<implementation: CharacteristicSpecies>>
> | }
> | EmptySetSpecies(L: LabelType): CombinatorialSpecies L == {
> |          CharacteristicSpecies(0$Integer)(L) add;
> | }
> | 
> | As you see, EmptySetSpecies is a function and its result type depends on 
> | its input type L.

> Yes. My question is whether "L" can be any value computed at runtime,
> or only values known at compile-time.  E.g., do you want to say
> 
>    * read in a Label l
>    * call CharacteristicSpecies with l
> 
> ?

Species can be substituted. I have not yet put this into the code, but 
in <<exports: CombinatorialSpecies>> you will find LabelType.

So I should be able to read m, n from the command line and say

extend String: LabelType == add;

(currently LabelType == PrimitiveType)

MySpec(L: LabelType): CombinatorialSpecies L == {
     CharacteristicSpecies(n)(CharacteristicSpecies m)(L) add;
}

In the middle of that you have the category

CombinatorialSpecies(CharacteristicSpecies m)

Is that enough to make things complicated?
BTW, I would not want to miss that power of Aldor.
MySpec is just a special case of a "Compose" constructor of species.

> If yes, evaluation at compile-time will be very limited.

Yes, I assume that is a big research topic to make such code efficient. 
I leave that to the compiler people. ;-)

> Or, would you be happy with Label values that are "known" to the
> compiler, from "simple" program text analysis?

The final goal for species is to work with them interactively. So I 
don't care if the interpreter in the middle of the session starts the 
compiler to produce some efficient code for me, but it should be 
possible to produce a "sufficiently efficient" standalone program.

And, in particular for species there seems to be need to call the compiler.

This here is another code piece.

BinaryTree(L: LabelType): CombinatorialSpecies L == {
         macro {
                 + == Plus;
                 * == Times;
                 1 == EmptySetSpecies;
                 X == SingletonSpecies;
                 B == BinaryTree;
         }
         (1 + X * B * B)(L) add;
}

For the full current status of that project see
svn://svn.risc.uni-linz.ac.at/hemmecke/combinat/trunk
and listen at aldor-combinat-devel at lists.sourceforge.net .

In general one would have a set of such recursive "equations". Writing 
my own interpreter for that must invoke the compiler. So I would like 
some language feature to start compilation, otherwise I take the input 
string write it out to a file, invoke the external compiler and then 
link the resulting library (I have no idea how the last thing is done).
But going the external way, my standalone program must know where the 
aldor compiler is on that system. :-(

> | > [ For example, C++ has dependent types at its "template systems" but
> | >   values are limited to integers and addresses of toplevel entities ]
> | 
> | Could you provide some example code? A link?
> 
> A simple example involving non-type parameter is the classical
> 
>    template<tyename T, int N>
>      struct buffer {
>        T data[N];
>      };
> 
> here the template buffer is parameterized by a type name and an
> integer.  Internally it holds an array of N Ts.  It can be used as
> 
>      buffer<int, 512> cache;
> 
> or
> 
>      buffer<char, 4 * 512> buf;
> 
> Notice that the integer argument is anything that can be evaluated at
> compile-time such as 512 or 4 * 512.  

I suspect that it is already hard to simplify 0+0 in Aldor. Suppose you 
write

Dom(X: with {0:%, +: (%, %)->%}): with {...} == add {
     Rep == X;
     local doubleZero: % == per(0 + 0);
     ...
}

The only thing a compiler can do is to produce a generic domain.
No lets suppose I give you the .ao library, but not the .as file.
Then you write a program that somewhere in the middle uses Dom(Integer) 
(where hopefully nobody had redefined 0 or + from Integer). Then I would 
like the executable having the equivalent of

    local doubleZero: Integer == 0;

as binary code. That is though, I guess. But as far as I know the 
current Aldor compiler is already doing such things.

Ralf



More information about the Aldor-l mailing list