[Aldor-l] [fricas-devel] Re: Package technicalities

Ralf Hemmecke ralf at hemmecke.de
Thu Jul 28 15:43:43 EDT 2011


>> But why would you want that anyway? What use case do you have in mind?
>
> I was thinking out exercises to help me better understand aldor,
> particularly what can be done with types being first-class objects. As
> such Zen exercise I took a function that returns a type of its
> argument --- I wanted to find out whether such function is possible or
> not and why.
>
> I came up with
>
> #include "aldor"
> #pile
>
> TypeFinder(S: Type): with
>      GetType: S ->  Type
> == add
>      GetType(x: S): Type == S
>
> I thought it to be a bit unpractical to import
> TypeFinder(TypeInQuestion) every time.
>
> But anyway the code above doesn't seem to work as I expected.

Yes, it cannot work. And the reason is quite simple. Aldor (and I'm 
pretty sure that the same holds for SPAD) doesn't store type information 
along with the object. In fact, "object" is the wrong word in the 
context of Aldor. If you have, for example, a variable v which is of 
type MachineInteger, then Aldor stores (on a 32bit computer) exactly 32 
bits. Not more. There is no bit that tells you (at runtime) what these 
32 bits mean. Every type information is dealt with (statically) at 
compile time.

If you want objects as in ordinary object oriented programming 
languages, you have to add the type information yourself. (See AUG page 
223.)

Your whole idea of asking for the runtime type is not appropriate for Aldor.

Ralf



More information about the Aldor-l mailing list