login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBox Aldor Semantics revision 1 of 5

1 2 3 4 5
Editor: 127.0.0.1
Time: 2007/11/11 11:37:39 GMT-8
Note: transferred from axiom-developer

changed:
-
The following Aldor code was given as an example by Ralf Hemmecke
and added to the wiki by Martin Rubey. See the thread:

http://lists.gnu.org/archive/html/axiom-developer/2006-07/msg00046.html

\begin{aldor}
#include "axiom"
define CatA: Category == with { }
define CatB: Category == with { }
define SomeCat: Category == with { CatA; CatB; }
Dom: SomeCat == Integer add;
A == Dom;
B: CatA == Dom;
H: CatA == Dom add;
main1():List Record(expression:String,result:Boolean) == [
  ["A has CatA",A has CatA],
  ["A has CatB",A has CatB],
  ["A has SomeCat",A has SomeCat],
  ["B has CatA",B has CatA],
  ["B has CatB",B has CatB],
  ["B has SomeCat",B has SomeCat],
  ["H has CatA",H has CatA],
  ["H has CatB",H has CatB],
  ["H has SomeCat",H has SomeCat]];

\end{aldor}

You get...
\begin{axiom}
main1()
)clear completely
\end{axiom}

In particular, that "B has CatB" is a bit surprising, isn't it?

Bill Page replied::
 
  I think you are dealing here with two separate but related issues:
  1) *static* typing, and 2) inheritance rules. All types in Aldor
  are static (or at least *nearly static*) meaning that they must be
  resolved during the compilation phase.

\begin{aldor}
#include "axiom"

define CatA: Category == with;
define CatB: Category == with;
define CatX: Category == with {CatA; CatB;}

A: Join(CatX, CatA) == add;
B: Join(CatX, CatB) == add;
import from Integer;
X: CatX == if odd? random(10) then A else B;
\end{aldor}

Try a little harder to create dynamic types:
\begin{aldor}
#include "axiom"

import from Integer;

define CatA: Category == with {n:Integer};
define CatB: Category == with {n:Integer};
define CatX: Category == with {n:Integer};

A: Join(CatX, CatA) == add { n:Integer==1 };
B: Join(CatX, CatB) == add { n:Integer==2 };
X1: CatX == if odd? random(10) then (A add) else (B add);
X2: CatX == if even? random(10) then (A add) else (B add);
\end{aldor}

\begin{axiom}
for i in 1..10 repeat output [n()$X1,n()$X2]
)clear completely
\end{axiom}

Or this way:
\begin{aldor}
#include "axiom"
import from Integer;

define CatA: Category == with {n:Integer};
define CatB: Category == with {n:Integer};
define CatX: Category == with {CatA; CatB; n:Integer};

A: Join(CatX, CatA) == add { n:Integer==1 };
B: Join(CatX, CatB) == add { n:Integer==2 };
Y1: CatX == if odd? random(10) then A else B;
Y2: CatX == if even? random(10) then A else B;
\end{aldor}

\begin{axiom}
for i in 1..10 repeat output [n()$Y1,n()$Y2]
)clear completely
\end{axiom}

Or like this:
\begin{aldor}
#include "axiom"
import from Integer;
define CatX: Category == with {foo: () -> Integer}
A: CatX == add {foo(): Integer == 0;}
B: CatX == add {foo(): Integer == 1;}
Z: CatX == if odd? random(10) then A else B;
\end{aldor}

\begin{axiom}
for i in 1..10 repeat output foo()$Z
)clear completely
\end{axiom}

Ralf Hemmecke asked:
Why does the compiler reject the program without the "add"
in line (*)?
\begin{aldor}
#include "axiom"

define CatA: Category == with;
define CatB: Category == with;
define CatX: Category == with;
A: CatX with { CatA } == add;
B: CatX with { CatB } == add;
X: CatX == if true then (A add) else (B add); -- (*)

main2():List Record(expression:String,result:Boolean) == [
  ["X has CatA",X has CatA],
  ["X has CatB",X has CatB],
  ["X has CatX",X has CatX]];

\end{aldor}

\begin{axiom}
main2()
)clear completely
\end{axiom}

Christian Aistleitner provided this answer:

I'd consider that a bug in comparison of exports. Replacing your (*) line  
by::

   X: CatX == if true then (A@CatX) else (B@CatX);

gives a working program.
\begin{aldor}
#include "axiom"

define CatA: Category == with;
define CatB: Category == with;
define CatX: Category == with;
A: CatX with { CatA } == add;
B: CatX with { CatB } == add;
X: CatX == if true then A@CatX else B@CatX; -- (*)

main3():List Record(expression:String,result:Boolean) == [
  ["X has CatA",X has CatA],
  ["X has CatB",X has CatB],
  ["X has CatX",X has CatX]];

\end{aldor}

\begin{axiom}
main3()
)clear completely
\end{axiom}

So the problem (wild guess) is that the compiler Has problems with  
seeing that the if statement gives CatX in both branches of the if  
statement. Mainly because the types of A and B aro not equal. However, you  
can hint the compiler. My code is telling him "The if part gives CatX and  
the else part gives CatX". Then the compiler can infer, that the whole  
"if" statement gives CatX. And it is at least the type of X (which is  
CatX). So it matches.

\begin{aldor}
#include "axiom"
import from Integer;
define CatA: Category == with;
define CatB: Category == with;
define CatX: Category == with;
A: Join(CatX, CatA) == add;
B: Join(CatX, CatB) == add;

MyPkg(X: CatX): with {isA?: () -> Boolean} == add {
	isA?(): Boolean == X has CatA;
}
main4(n:Integer): Boolean == {
	X: CatX == if zero? n then (A@CatX) else (B@CatX);
	isA?()$MyPkg(X);
}
\end{aldor}

\begin{axiom}
main4(0)
main4(1)
)clear completely
\end{axiom}




In the following code we have the correspondence::

    A      <--> B
    String <--> with
    "x"    <--> String
    "y"    <--> Integer

\begin{aldor}
#include "axiom"
define CatA(s: String): Category == with;
A(s: String): CatA(s) == add;

define CatB(s: with): Category == with;
B(s: with): CatB(s) == add;

rhxmain(): List Record(s: String, b: Boolean) == [
    ["A x has CatA x", (A("x") has CatA("x"))],
    ["A y has CatA x", (A("y") has CatA("x"))],
    ["B String has CatB String", (B(String)  has CatB(String))],
    ["B Integer has CatB String",(B(Integer) has CatB(String))]
];
\end{aldor}

The interesting part is that the truth value of the second and fourth list elements do not agree.
\begin{axiom}
rhxmain()
)clear completely
\end{axiom}

<a name="variable"/>
An example of a domain-valued variable
\begin{aldor}
#include "axiom"
#pile

main5(n:Integer):List Boolean ==
  local x:IntegralDomain
  local y:Category

  if n=1 then
    y := Field
  else
    y := Ring

  x := Integer
  test1:Boolean := x has y
  x := Fraction Integer
  test2:Boolean := x has y
  [test1,test2]
\end{aldor}

\begin{axiom}
main5(1)
main5(2)
)clear completely
\end{axiom}

The compiler checks static types.
\begin{aldor}
#include "axiom"
#pile

main6():List Boolean ==
  local x:IntegralDomain

  x := Integer
  test1:Boolean := x has Field
  x := String
  test2:Boolean := x has Field
  [test1,test2]
\end{aldor}

But note that we cannot define domain-valued variables in
the Axiom interpreter.
\begin{axiom}
  x:IntegralDomain
\end{axiom}

From BillPage Wed Jul 26 06:28:37 -0500 2006
From: Bill Page
Date: Wed, 26 Jul 2006 06:28:37 -0500
Subject: Try to write a self-describing domain
Message-ID: <20060726062837-0500@wiki.axiom-developer.org>

\begin{aldor}
#include "axiom"
#pile

MyDom: with
  sigs:List Category
  add2:(MyDom,MyDom) -> MyDom
  sub2:(MyDom,MyDom) -> MyDom
  neg: MyDom -> MyDom
 == add
  import from Integer
  Rep == Integer

  sigs:List Category ==
    [with {add2:(MyDom,MyDom)->MyDom},
     with {sub2:(MyDom,MyDom)->MyDom},
     with {neg:MyDom->MyDom}]

  add2(x:%,y:%):% == per(rep(x) + rep(y))
  sub2(x:%,y:%):% == per(rep(x) - rep(y))
  neg(x:%):% == per(-rep(x))

main8():List Boolean ==
  import from ListFunctions2(Category,Boolean)

  map((i:Category):Boolean+->(MyDom has i), sigs$MyDom)
\end{aldor}

\begin{axiom}
)sh MyDom
main8()
\end{axiom}


The following Aldor code was given as an example by Ralf Hemmecke and added to the wiki by Martin Rubey. See the thread:

http://lists.gnu.org/archive/html/axiom-developer/2006-07/msg00046.html

aldor
#include "axiom"
define CatA: Category == with { }
define CatB: Category == with { }
define SomeCat: Category == with { CatA; CatB; }
Dom: SomeCat == Integer add;
A == Dom;
B: CatA == Dom;
H: CatA == Dom add;
main1():List Record(expression:String,result:Boolean) == [
  ["A has CatA",A has CatA],
  ["A has CatB",A has CatB],
  ["A has SomeCat",A has SomeCat],
  ["B has CatA",B has CatA],
  ["B has CatB",B has CatB],
  ["B has SomeCat",B has SomeCat],
  ["H has CatA",H has CatA],
  ["H has CatB",H has CatB],
  ["H has SomeCat",H has SomeCat]];
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./3788028526442996283-25px001.lsp
   Issuing )library command for 3788028526442996283-25px001
   Reading /var/zope2/var/LatexWiki/3788028526442996283-25px001.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001
   CatA is now explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001
   Dom is now explicitly exposed in frame initial 
   Dom will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001
   CatB is now explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001
   SomeCat is now explicitly exposed in frame initial 
   SomeCat will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001
   H is now explicitly exposed in frame initial 
   H will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3788028526442996283-25px001

You get...

axiom
main1()
LatexWiki Image(1)
Type: List Record(expression: String,result: Boolean)
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

In particular, that "B has CatB?" is a bit surprising, isn't it?

Bill Page replied:

  I think you are dealing here with two separate but related issues:
  1) *static* typing, and 2) inheritance rules. All types in Aldor
  are static (or at least *nearly static*) meaning that they must be
  resolved during the compilation phase.

aldor
#include "axiom"
define CatA: Category == with; define CatB: Category == with; define CatX: Category == with {CatA; CatB;}
A: Join(CatX, CatA) == add; B: Join(CatX, CatB) == add; import from Integer; X: CatX == if odd? random(10) then A else B;
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/934600477956551444-25px003.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./934600477956551444-25px003.lsp
   Issuing )library command for 934600477956551444-25px003
   Reading /var/zope2/var/LatexWiki/934600477956551444-25px003.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/934600477956551444-25px003
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/934600477956551444-25px003
   X is now explicitly exposed in frame initial 
   X will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/934600477956551444-25px003
   CatA is now explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/934600477956551444-25px003
   CatB is now explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/934600477956551444-25px003
   CatX is now explicitly exposed in frame initial 
   CatX will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/934600477956551444-25px003

Try a little harder to create dynamic types:

aldor
#include "axiom"
import from Integer;
define CatA: Category == with {n:Integer}; define CatB: Category == with {n:Integer}; define CatX: Category == with {n:Integer};
A: Join(CatX, CatA) == add { n:Integer==1 }; B: Join(CatX, CatB) == add { n:Integer==2 }; X1: CatX == if odd? random(10) then (A add) else (B add); X2: CatX == if even? random(10) then (A add) else (B add);
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./4046171615798297799-25px004.lsp
   Issuing )library command for 4046171615798297799-25px004
   Reading /var/zope2/var/LatexWiki/4046171615798297799-25px004.asy
   A is already explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004
   B is already explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004
   CatA is already explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004
   X1 is now explicitly exposed in frame initial 
   X1 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004
   CatB is already explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004
   X2 is now explicitly exposed in frame initial 
   X2 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004
   CatX is already explicitly exposed in frame initial 
   CatX will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/4046171615798297799-25px004

axiom
for i in 1..10 repeat output [n()$X1,n()$X2]
[1,1] [1,1] [1,1] [1,1] [1,1] [1,1] [1,1] [1,1] [1,1] [1,1]
Type: Void
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

Or this way:

aldor
#include "axiom"
import from Integer;
define CatA: Category == with {n:Integer}; define CatB: Category == with {n:Integer}; define CatX: Category == with {CatA; CatB; n:Integer};
A: Join(CatX, CatA) == add { n:Integer==1 }; B: Join(CatX, CatB) == add { n:Integer==2 }; Y1: CatX == if odd? random(10) then A else B; Y2: CatX == if even? random(10) then A else B;
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./3471379723332304579-25px006.lsp
   Issuing )library command for 3471379723332304579-25px006
   Reading /var/zope2/var/LatexWiki/3471379723332304579-25px006.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006
   CatA is now explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006
   CatB is now explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006
   Y1 is now explicitly exposed in frame initial 
   Y1 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006
   CatX is now explicitly exposed in frame initial 
   CatX will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006
   Y2 is now explicitly exposed in frame initial 
   Y2 will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/3471379723332304579-25px006

axiom
for i in 1..10 repeat output [n()$Y1,n()$Y2]
[2,1] [2,1] [2,1] [2,1] [2,1] [2,1] [2,1] [2,1] [2,1] [2,1]
Type: Void
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

Or like this:

aldor
#include "axiom"
import from Integer;
define CatX: Category == with {foo: () -> Integer}
A: CatX == add {foo(): Integer == 0;}
B: CatX == add {foo(): Integer == 1;}
Z: CatX == if odd? random(10) then A else B;
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/5702025508533234167-25px008.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./5702025508533234167-25px008.lsp
   Issuing )library command for 5702025508533234167-25px008
   Reading /var/zope2/var/LatexWiki/5702025508533234167-25px008.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/5702025508533234167-25px008
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/5702025508533234167-25px008
   Z is now explicitly exposed in frame initial 
   Z will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/5702025508533234167-25px008
   CatX is now explicitly exposed in frame initial 
   CatX will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/5702025508533234167-25px008

axiom
for i in 1..10 repeat output foo()$Z
0 0 0 0 0 0 0 0 0 0
Type: Void
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

Ralf Hemmecke asked: Why does the compiler reject the program without the "add" in line (*)?

aldor
#include "axiom"
define CatA: Category == with; define CatB: Category == with; define CatX: Category == with; A: CatX with { CatA } == add; B: CatX with { CatB } == add; X: CatX == if true then (A add) else (B add); -- (*)
main2():List Record(expression:String,result:Boolean) == [ ["X has CatA",X has CatA], ["X has CatB",X has CatB], ["X has CatX",X has CatX]];
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/7712043450922662837-25px010.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./7712043450922662837-25px010.lsp
   Issuing )library command for 7712043450922662837-25px010
   Reading /var/zope2/var/LatexWiki/7712043450922662837-25px010.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7712043450922662837-25px010
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7712043450922662837-25px010
   X is now explicitly exposed in frame initial 
   X will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7712043450922662837-25px010
   CatA is now explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7712043450922662837-25px010
   CatB is now explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7712043450922662837-25px010
   CatX is now explicitly exposed in frame initial 
   CatX will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7712043450922662837-25px010

axiom
main2()
LatexWiki Image(2)
Type: List Record(expression: String,result: Boolean)
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

Christian Aistleitner provided this answer:

I'd consider that a bug in comparison of exports. Replacing your (*) line by:

   X: CatX == if true then (A@CatX) else (B@CatX);

gives a working program.

aldor
#include "axiom"
define CatA: Category == with; define CatB: Category == with; define CatX: Category == with; A: CatX with { CatA } == add; B: CatX with { CatB } == add; X: CatX == if true then A@CatX else B@CatX; -- (*)
main3():List Record(expression:String,result:Boolean) == [ ["X has CatA",X has CatA], ["X has CatB",X has CatB], ["X has CatX",X has CatX]];
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/1208324321343406004-25px012.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./1208324321343406004-25px012.lsp
   Issuing )library command for 1208324321343406004-25px012
   Reading /var/zope2/var/LatexWiki/1208324321343406004-25px012.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1208324321343406004-25px012
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1208324321343406004-25px012
   X is now explicitly exposed in frame initial 
   X will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1208324321343406004-25px012
   CatA is now explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1208324321343406004-25px012
   CatB is now explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1208324321343406004-25px012
   CatX is now explicitly exposed in frame initial 
   CatX will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1208324321343406004-25px012

axiom
main3()
LatexWiki Image(3)
Type: List Record(expression: String,result: Boolean)
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

So the problem (wild guess) is that the compiler Has problems with seeing that the if statement gives CatX? in both branches of the if statement. Mainly because the types of A and B aro not equal. However, you can hint the compiler. My code is telling him "The if part gives CatX? and the else part gives CatX?". Then the compiler can infer, that the whole "if" statement gives CatX?. And it is at least the type of X (which is CatX?). So it matches.

aldor
#include "axiom"
import from Integer;
define CatA: Category == with;
define CatB: Category == with;
define CatX: Category == with;
A: Join(CatX, CatA) == add;
B: Join(CatX, CatB) == add;
MyPkg(X: CatX): with {isA?: () -> Boolean} == add { isA?(): Boolean == X has CatA; } main4(n:Integer): Boolean == { X: CatX == if zero? n then (A@CatX) else (B@CatX); isA?()$MyPkg(X); }
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/6804229532583544981-25px014.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./6804229532583544981-25px014.lsp
   Issuing )library command for 6804229532583544981-25px014
   Reading /var/zope2/var/LatexWiki/6804229532583544981-25px014.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/6804229532583544981-25px014
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/6804229532583544981-25px014
   MyPkg is now explicitly exposed in frame initial 
   MyPkg will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/6804229532583544981-25px014
   CatA is now explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/6804229532583544981-25px014
   CatB is now explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/6804229532583544981-25px014
   CatX is now explicitly exposed in frame initial 
   CatX will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/6804229532583544981-25px014

axiom
main4(0)
LatexWiki Image(4)
Type: Boolean
axiom
main4(1)
LatexWiki Image(5)
Type: Boolean
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

In the following code we have the correspondence:

    A      <--> B
    String <--> with
    "x"    <--> String
    "y"    <--> Integer

aldor
#include "axiom"
define CatA(s: String): Category == with;
A(s: String): CatA(s) == add;
define CatB(s: with): Category == with; B(s: with): CatB(s) == add;
rhxmain(): List Record(s: String, b: Boolean) == [ ["A x has CatA x", (A("x") has CatA("x"))], ["A y has CatA x", (A("y") has CatA("x"))], ["B String has CatB String", (B(String) has CatB(String))], ["B Integer has CatB String",(B(Integer) has CatB(String))] ];
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/7724360379013079758-25px016.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./7724360379013079758-25px016.lsp
   Issuing )library command for 7724360379013079758-25px016
   Reading /var/zope2/var/LatexWiki/7724360379013079758-25px016.asy
   A is now explicitly exposed in frame initial 
   A will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7724360379013079758-25px016
   B is now explicitly exposed in frame initial 
   B will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7724360379013079758-25px016
   CatA is now explicitly exposed in frame initial 
   CatA will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7724360379013079758-25px016
   CatB is now explicitly exposed in frame initial 
   CatB will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7724360379013079758-25px016

The interesting part is that the truth value of the second and fourth list elements do not agree.

axiom
rhxmain()
LatexWiki Image(6)
Type: List Record(s: String,b: Boolean)
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

An example of a domain-valued variable

#include "axiom"
#pile
main5(n:Integer):List Boolean == local x:IntegralDomain local y:Category
if n=1 then y := Field else y := Ring
x := Integer test1:Boolean := x has y x := Fraction Integer test2:Boolean := x has y [test1,test2]
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/1586618870818532942-25px018.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./1586618870818532942-25px018.lsp
   Issuing )library command for 1586618870818532942-25px018
   Reading /var/zope2/var/LatexWiki/1586618870818532942-25px018.asy

axiom
main5(1)
LatexWiki Image(7)
Type: List Boolean
axiom
main5(2)
LatexWiki Image(8)
Type: List Boolean
axiom
)clear completely
All user variables and function definitions have been cleared. All )browse facility databases have been cleared. Internally cached functions and constructors have been cleared. )clear completely is finished.

The compiler checks static types.

aldor
#include "axiom"
#pile
main6():List Boolean == local x:IntegralDomain
x := Integer test1:Boolean := x has Field x := String test2:Boolean := x has Field [test1,test2]
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/395909315557564304-25px020.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
"/var/zope2/var/LatexWiki/395909315557564304-25px020.as", line 9: 
  x := String
.......^
[L9 C8] #2 (Error) There is no suitable interpretation for the expression String
  The context requires an expression of type IntegralDomain.
     The possible types of the right hand side (`String') are:
          -- Join(
                 with 
                    ==  add ()
  ...
The )library system command was not called after compilation.

But note that we cannot define domain-valued variables in the Axiom interpreter.

axiom
x:IntegralDomain
IntegralDomain is a category, not a domain, and declarations require domains.

Try to write a self-describing domain --Bill Page, Wed, 26 Jul 2006 06:28:37 -0500 reply
aldor
#include "axiom"
#pile
MyDom: with sigs:List Category add2:(MyDom,MyDom) -> MyDom sub2:(MyDom,MyDom) -> MyDom neg: MyDom -> MyDom == add import from Integer Rep == Integer
sigs:List Category == [with {add2:(MyDom,MyDom)->MyDom}, with {sub2:(MyDom,MyDom)->MyDom}, with {neg:MyDom->MyDom}]
add2(x:%,y:%):% == per(rep(x) + rep(y)) sub2(x:%,y:%):% == per(rep(x) - rep(y)) neg(x:%):% == per(-rep(x))
main8():List Boolean == import from ListFunctions2(Category,Boolean)
map((i:Category):Boolean+->(MyDom has i), sigs$MyDom)
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/7325620604487185069-25px022.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./7325620604487185069-25px022.lsp
   Issuing )library command for 7325620604487185069-25px022
   Reading /var/zope2/var/LatexWiki/7325620604487185069-25px022.asy
   MyDom is now explicitly exposed in frame initial 
   MyDom will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/7325620604487185069-25px022

axiom
)sh MyDom
MyDom is a domain constructor Abbreviation for MyDom is MYDOM This constructor is exposed in this frame. Issue )edit 7325620604487185069-25px022.as to see algebra source code for MYDOM
------------------------------- Operations -------------------------------- add2 : (MyDom,MyDom) -> MyDom neg : MyDom -> MyDom sigs : () -> List Category sub2 : (MyDom,MyDom) -> MyDom
main8()
>> System error: Caught fatal error [memory may be damaged]