Hello,

looks like I've missed all the fun already, but here go my 2 cents:

> getit(T: Category, L: Tuple T, i: I): T == (element(L, i)$Tuple(T)) add;

getit lives at the top-level. It is not too straight forward (at least it  
hasn't been for me) to get it into MyTuple, as adding a function
   getit: I -> T;
to the with and
   getit(i: I): T == (element(L, i)$Tuple(T)) add;
to the add part of MyTuple, the compiler complained about missing exports.  
However, the problem is solved by _not_ using abbreviated syntax and  
putting
   getit: MachineInteger -> T == ( i: MachineInteger ):T +-> {(element(L,  
i)$Tuple(T)) add };
in the add part of MyTuple. However, I am not too sure whether you really  
want to have getit and its add. It constructs a new domain again and again  
for the same thing. Only by pretends you ignore lots of these generated  
domains and somehow manage to get things done.
Furthermore, the use of add within getit cuts off every function exceeding  
T (Ralf already gave some pointers in this direction). So when you  
construct a
   MyTuple( OutputType, ... )
and put in something having PrimitiveType (e.g.: Boolean), the result of  
getit has lost PrimitiveType.

To me, getting the value without the corresponding type is not in the  
spirit of a fully typed language.  Therefore, I suggest to drop your get  
method alltogether, and give a get method returning a pair of value and  
its type.
However, for some cases it might make sense to have the type of a slot in  
a MyTuple without its value. So for convenience it might prove valuable to  
have a "getType" function.

The following piece of code implements my suggestions.

#include "aldor"
import from Trace, MachineInteger, Integer, String, TextWriter, Character;

macro I == MachineInteger;

Object: with {
           object: (T: PrimitiveType, T) -> %;
           avail:  % -> (T: PrimitiveType, T);
}
== add {
           Rep == Record(T: PrimitiveType, val: T);
           import from Rep;
           object  (T: PrimitiveType, t:  T) : %    == per [T, t];
           avail   (ob: %) : (T: PrimitiveType,  T) == explode rep ob;
}

------------------------------------------------------------------

MyTuple(T: Category, L: Tuple T): with {
          new: List Object -> %;
          get: (i: I, %) -> ( U: T, u: U );
          getType: (i: I, %) -> T;
} == add {
          Rep == List Object;
          import from Rep;
          new(a: List Object): % == per a;
          get(i: I, x: %): ( U: T, u: U ) == {
                  X: List Object := rep x;
                  import from Object;
                  avail(X.i);
          }
          getType(i: I, x: %): T == {
                  ( U, u ) == get( i, x );
                  U;
          }
}

import from Integer, Object, List Object, Boolean, I;
t: Tuple OutputType == (Integer, Boolean);
li : List Object := [object(Integer, 17), object(Boolean, true)];
import from MyTuple(OutputType, t);
m == new li;

process( X: OutputType, x: X ):() == {
         stdout << "X does";
         if not (X has PrimitiveType) then
         {
           stdout << " not";
         }
         stdout << " provide PrimitveType" << newline;
         stdout << x << newline;
}

stdout << "==== 1 ====" << newline;
( U1, u1 ) == get(1,m);
process( U1, u1 );

stdout << "==== 2 ====" << newline;

( U2, u2 ) == get(2,m);
process( U2, u2 );

stdout << "==== END ====" << newline;



Output:
==== 1 ====
X does provide PrimitveType
17
==== 2 ====
X does provide PrimitveType
T
==== END ====

Note also, that the function "process" requires its parameter X to be of  
OutputType. When calling the function "process", there is no need to test  
U1 for OutputType via "U1 has OutputType". Aldor already _knows_ that U1  
has OutputType, as MyTuple is built over OutputTypes.

Kind regards,
Christian

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Aldor-combinat-devel mailing list
Aldor-combinat-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/aldor-combinat-devel

Reply via email to