axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] Re: [Aldor-l] exports and constants


From: Christian Aistleitner
Subject: [Axiom-developer] Re: [Aldor-l] exports and constants
Date: Fri, 21 Jul 2006 09:47:11 +0200
User-agent: Opera Mail/9.00 (Linux)

Hello,

On Fri, 21 Jul 2006 02:12:17 +0200, Ralf Hemmecke <address@hidden> wrote:

There is a difference in the semantic, but I cannot
remember that I have found a proper explanation of what
"Ident: SomeType == Dom" actually means (no "add" here).

In the above the value of 'Ident' *is* 'Dom' whereas in the
previous case 'Ident' is the name of a new domain whose
"parent domain" is 'Dom' - like the difference between

If Ident *is* Dom then what do you think the ": SomeType" is for?

May it's syntactic sugar (maybe I should drop the "syntactic").
You can use it to restrict the static type.
Example:


#include "aldor"
import from String, TextWriter, Character;

define CatA: Category == with { }
define CatB: Category == with { }
define SomeCat: Category == with { CatA; CatB; }
Dom: SomeCat == Integer add;

B: CatA == Dom;

stdout << "B has CatA: " << ( B has CatA ) << newline;
stdout << "B has CatB: " << ( B has CatB ) << newline;

func( DomParam: CatB ):() == { stdout << "called func" << newline; }


C_ALL=C /opt/aldor/bin/aldor -M no-abbrev -C args=-Wopts=-m32 -Fx -lalgebra -laldor -D IFCLAUSE test2.as && ./test2
cc1: note: -fwritable-strings is deprecated; see documentation for details
cc1: note: -fwritable-strings is deprecated; see documentation for details
B has CatA: T
B has CatB: T


We see B's dynamic type has bath CatA and CatB.
However,
func( B )
complains about B being only CatA and not also CatB.
func( Dom )
works.

What about the following:

Universe of the compiler before B: CatA == DOM:

Dom ( StaticType: SomeCat; Implementation at memory location 123456 )

After the B: CatA == Dom:

Dom ( StaticType: SomeCat; Implementation at memory location 123456 )
B   ( StaticType: CatA;    Implementation at memory location 123456 )


---BEGIN aaa5.as
#include "aldor"
define CatA: Category == with;
define CatB: Category == with;
define CatX: Category == with;

A: Join(CatX, CatA) == add;
B: Join(CatX, CatB) == add;
#if ADD
import from MachineInteger;
X: CatX == if odd? random(10) then (A add) else (B add);
#else
X: CatX == if true then A else B;
#endif
---END aaa5.as

 >aldor -fx -laldor -DADD aaa5.as

compiles without any complaints. Now try without the ADD assertion.

 >aldor -fx -laldor aaa5.as
"aaa5.as", line 14: X: CatX == if true then A else B;
                     ...........^
[L14 C12] #1 (Error) Have determined 0 possible types for the expression.
   Subexpression `A':
        Meaning 1:
                 Join(CatX, CatA) with
                     ==...
   Subexpression `B':
        Meaning 1:
                 Join(CatX, CatB) with
                     ==...
   The context requires an expression of type CatX.


Are you now a bit more puzzled?

Random things are not the problem. Obviously "A" and "A add" are not
(treated) identical by the compiler.

It's getting tricky to put my thoughts into correct words, but I guess:
Once the value of "A" and "A add" are established, they are treated equally. But these expressions give different values. "A add" gives an expression of type CatX. "A" gives an expression of type Join( CatX, CatA ). And the compiler cannot infer properly, that Join( CatX, CatA ) provides CatX.

Now if we assume that

X: CatX == if true then A else B;

yield an X of the type of the domain on the right hand side then the
compiler has to match the types of A and B (they have to be equal).
Try to replace B by A in the code above and the compiler will not
complain anymore.

Not true for me--I still get the corresponding errors:

#include "aldor"
define CatA: Category == with;
define CatB: Category == with;
define CatX: Category == with;

A: Join(CatX, CatA) == add;
B: Join(CatX, CatB) == add;

X: CatX == if true then B else A;



LC_ALL=C /opt/aldor/bin/aldor -M no-abbrev -C args=-Wopts=-m32 -Fx -lalgebra -laldor test2.as && ./test2
"test2.as", line 34: X: CatX == if true then B else A;
                     ...........^
[L34 C12] #1 (Error) Have determined 0 possible types for the expression.
  Subexpression `B':
        Meaning 1:
                Join(CatX, CatB) with
                    ==  add ()

  Subexpression `A':
        Meaning 1:
                Join(CatX, CatA) with
                    ==  add ()

  The context requires an expression of type CatX.




---BEGIN aaa6.as
#include "aldor"
#include "aldorio"
macro I == MachineInteger;
define CatX: Category == with {foo: () -> I}
A: CatX == add {foo(): I == 0;}
B: CatX == add {foo(): I == 1;}

import from MachineInteger;
X: CatX == if odd? random(10) then A else B;

main(): () == {
        import from X;
        stdout << foo() << newline;
}
main();
---END aaa6.as

[ ... ]

The interesting part of aaa6.as is that now if one writes

X: CatX == if odd? random(10) then (A add) else (B add);

(with the "add"), the program does not compile anymore in contrast to
aaa5.as above.

 >aldor -fx -laldor aaa6.as
"aaa6.as", line 13:         stdout << foo() << newline;
                     ..................^
[L13 C19] #1 (Error) There are no suitable meanings for the operator `foo'.

But I guess, that's a different issue, as X has the foo function and allows to call it, as demonstrated by

#include "aldor"
#include "aldorio"
macro I == MachineInteger;
define CatX: Category == with {foo: () -> I}
A: CatX == add {foo(): I == 0;}
B: CatX == add {foo(): I == 1;}
import from MachineInteger;
X: CatX == if odd? random(10) then (A add) else (B add);
main(): () == {
        import from X;

        stdout << (X has with{ foo:() -> I }) << newline;
        stdout << ((foo$X)()) << newline;
}
main();

LC_ALL=C /opt/aldor/bin/aldor -M no-abbrev -C args=-Wopts=-m32 -Fx -lalgebra -laldor test2.as && ./test2 && sleep 1 && ./test2
cc1: note: -fwritable-strings is deprecated; see documentation for details
cc1: note: -fwritable-strings is deprecated; see documentation for details
T
1
T
0

--
Kind regards,
Christian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]