[Aldor-l] [Aldor-combinat-devel] parametric types and instantiation

Christian Aistleitner tmgisi at gmx.at
Sat Oct 28 07:16:26 EDT 2006


Hello,

On Thu, 26 Oct 2006 13:38:10 +0200, Ralf Hemmecke <ralf at hemmecke.de> wrote:

>> #include "aldor"
>>
>> import from String;
>> import from TextWriter, Character, MachineInteger;
>>
>>
>> Cat: Category == with {
>> 	getMagicNumber: () -> MachineInteger;
>> };
>>
>> Dom( a: MachineInteger ): Cat == add {
>> 	stdout << "initializing with " << a << newline;
>> 	getMagicNumber(): MachineInteger == {
>> 		a;
>> 	}
>> }
>>
>>
>> func( EDom: Cat ): () == {
>> 	EEDom: Cat == EDom add;
>> 	import from EEDom;
>> 	stdout << getMagicNumber() << newline;
>> }
>>
>> func( Dom( 1 ) );
>> func( Dom( 1 ) );
>>
>>
>> Dom( 1 ) does not appear in type context directly. Hence it should be
>> instantiated twice. And it is instantiated twice:
>
> Hmmm, I agree that the AUG does not prevent a double instantiation.

That was the important part of my example. The rest is not so important.

> It
> actually leaves it open when and if at all domain-valued functions are
> evaluated. With that understanding I would agree to
>
> 	"Hence it *could* be instantiated twice."
>
> but I hesitate to say it _should_. I don't think the AUG says something
> that forces double instantiation in the case above.

I have not yet made up my mind, whether or not I like that statement. But  
my aim is to have Aldor keywords allowing to override Aldor's choice of  
whether or not a function is meant functional or not.
So I am probably too biased anyways.

> On top-level you use Dom(1) twice as function arguments for Dom(1). So
> in that context it should be the same.

Why? I did not get them into type-context yet. Did I?

> And interestingly it is. Just add
> two lines
>
> ---BEGIN aaa.as
> #include "test.as" -- code from above
> stdout << getMagicNumber()$Dom(1) << newline;
> stdout << getMagicNumber()$Dom(1) << newline;
> ---END aaa.as
>
> at the end of your program.

When adding these two lines, you change the meaning of Dom(1). By the  
...$Dom(1) part, you get Dom(1) into type context. Hence, the Dom(1) of  
func( Dom( 1 ) ) may refer to the Dom(1) introduced by the type context.

> The output then is:
>
>  >aldor -M no-abbrev -grun -l aldor aaa.as
> initializing with 1
> 1
> initializing with 1
> 1
> initializing with 1
> 1
> 1
>
> Dom(1) gets instantiated 3 times, not 2 and not 4.
> I guess, that is also perfectly OK for Christian.

I would have hoped, Dom is evaluated only once at 1, due to the introduced  
type context. However, according to the AUG, any number between 1 and 4 is  
valid.

> Maybe the line that triggers the first two instantiations of Dom(1) is
>
>  > 	EEDom: Cat == EDom add;

I think so. Yes.

> Here EEDom is basically a copy of Dom(1). Maybe that is the reason why
> Dom(1) is instantiated in each call of "func(Dom(1))".

At least, that has been my intention when writing the code.
However, such details are beyond the original intention of the program. I  
just wanted to give a short example where Aldor evaluates a domain  
building function twice at the same parameter.

--
Kind regards,
Christian




More information about the Aldor-l mailing list