[Aldor-l] FUD (was: Re: [Aldor-combinat-devel] parametric types and instantiation)
Christian Aistleitner
tmgisi at gmx.at
Sun Oct 29 03:44:59 EST 2006
Hello,
On Sat, 28 Oct 2006 18:55:11 +0200, Ralf Hemmecke <ralf at hemmecke.de> wrote:
>>>> 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:
>
> Hey Christian, I am amazed. I now believe you are right.
>
> If Dom(1) appears twice as an argument of a function "func" then it is
> not in a type context and *must* be evaluated [...]
I probably should not comment on these things, as I do not know these
things well. But you addressed me personally, so I'll present my two cents
anyways. Let's get to your code:
> ---BEGIN aaa.as
> #include "aldor"
> #include "aldorio"
> macro I == MachineInteger;
> import from I;
> Cat: Category == with {getMagicNumber: () -> I}
> Dom(a: I): Cat == add {
> stdout << "initializing with " << a << newline;
> getMagicNumber(): I == a;
> }
> func(EDom: Cat): () == stdout << getMagicNumber()$EDom << newline;
> func(Dom 1);
> func(Dom 1);
> ---END aaa.as
>
> gives (at least on my computer with aldor v1.0.2/3):
>
> >aldor -M no-abbrev -grun -l aldor aaa.as
> initializing with 1
> 1
> 1
Lots and lots of nasty things might happen, when playing around with the
code I originally gave. The most misty thing is lazy evaluation. Both of
“lazy” and “evaluation” may cause problems.
Maybe the function Dom _is_ evaluated at 1 twice, but we do not know it ;)
Does not seem probable to me.
The problem is, what is meant by “evaluate” for domain building functions.
Domain building functions are expected to return domains.
But when is a domain a domain?
Assume all the data structures for a domain are prepared, functions parsed
and everything done except the “add” part has not been executed.
At this point you know the name of the domain and it's function signatures.
To me, you could already call it a domain. The relevant parts of the “add”
are executed as they are needed.
But you cannot trace such preparations within Aldor. You'd have to step
down to C or fire up a C debugger.
However, assume something like that would happen within Aldor. This would
allow to instantiate Dom( 1 ) twice. And still via some identification
techniques, Aldor could infer that it may recycle EDom within func, so
that there are two domains prepared in memory, but the add part of only
one domain is evaluated.
Rather improbable, but possible. And contradicting several implicit
assumption one typically has about domains.
Another possibility would be that “type context” acts on a different
scope. To me, this contradicts the AUG again, but is more probable.
Aldor may hold a global repository of domains. Each domain every
instantiated is held there and may be looked up.
The first “func( Dom( 1 ) )” creates the domain (or does so within the
func's ...$EDom statement). On executing the second “func( Dom ( 1 ) )”
statement, Aldor realizes that there is already a domain “Dom ( 1 )” in
the repository and reuses it.
Aldor forgets about “type context” in this szenario. But I guess that
there is more to “type context” than written in the AUG anyway.
There are lots of further possibilities. I just wanted to give a rather
far-stretched one and a probable one.
I do not have the faintest idea what is really happenning.
But it's not important enough to me right now to spend days or weeks in
front of gdb to get to the bottom of this issue. If someone does, I'd be
more than happy to hear about the results.
--
Kind regards,
Christian
More information about the Aldor-l
mailing list