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

**On Date: Jun 26, 2007 8:19 AM Ralf Hemmecke wrote:((

Suppose you want a constructor like:

  M(T: Tuple Cat): MCat(T) == add {...}

for some given category Cat (For simplicity, lets say:

   define Cat: Category == with {=:(%,%)->Boolean}

The question now is how do I define MCat? and the corresponding add {...} in such a way that I am able to generate an element of M in a simple form.

Basically, I want to say:

  import from Integer, String, Boolean;
  import from M(Integer, String);
  import from M(String, String, Boolean);
  a := m(4,"a");
  b := m("x", "y", true);

Do you have an idea how to define the function m generically?

Also I would probably like to have:

  s: String := b.2;
  i: Integer := a.1;
  q: Boolean := b.3;

Try to define this apply function.

Important, I want to have as much type safety as possible, i.e. If I would have written:

  c := m(1, "x", false);

the compiler should already shout that the type of the first argument doesn't fit.

Good luck.


Bill Page wrote:

Here is a first attempt. It sort of works, but there are problems.

aldor
#pile
#include "axiom.as"
--
M(T: Tuple Type): with
    m: T -> %
    get: % -> T
  == add
    m(x:T):% == (x) pretend %
    get(x:%):T == x pretend T
aldor
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mm.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mm.as", line 4: M(T: Tuple Type): with .....^.....^ [L4 C6] #9 (Error) There are no suitable meanings for the operator `Tuple'. [L4 C12] #10 (Error) No meaning for identifier `Type'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mm.as", line 5: m: T -> % .......^ [L5 C8] #11 (Error) There are 0 meanings for `T' in this context. The possible types were: T: Tuple(Type), a local The context requires an expression of type Tuple(Type).
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mm.as", line 6: get: % -> T ...........^ [L6 C12] #12 (Error) There are no suitable meanings for the operator `->'. [L6 C12] #13 (Fatal Error) Too many errors (use `-M emax=n' or `-M no-emax' to change the limit).
The )library system command was not called after compilation.

fricas
)show M
The )show system command is used to display information about types or partial types. For example, )show Integer will show information about Integer .
M is not the name of a known type constructor. If you want to see information about any operations named M , issue )display operations M

Unfortunately the Axiom interpreter does not understand Tuple Type

fricas
a := m(4,"a")$M(Integer,String)
There are no library operations named M Use HyperDoc Browse or issue )what op M to learn if there is any operation containing " M " in its name.
Cannot find a definition or applicable library operation named M with argument type(s) Type Type
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

But this can be written in Aldor

aldor
#pile
#include "axiom.as"
#library mm "mm.ao"
import from mm
inline from mm
--
main():Record(i:String,j:String,k:Boolean) ==
  import from Integer, String, Boolean
  import from M(Integer, String)
  import from M(String, String, Boolean)
a := m(4,"a"); b := m("x", "y", true) -- -- type error: -- c := m(1, "x", false) -- (i,j,k):=get(b) [i,j,k]
aldor
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1927112369448499588-25px004.as
      using AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Could not use archive file `libaxiom.al'.
#2 (Warning) Could not use archive file `libaxiom.al'.
#9 (Warning) Could not use archive file `libaxiom.al'.
Program fault (segmentation violation).#10 (Error) Program fault (segmentation violation).
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4: 
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier `AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15: import { true: %, false: % } from Boolean; ..................................^ [L15 C35] #4 (Error) No meaning for identifier `Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17: string: Literal -> %; ........................^.......^ [L17 C25] #5 (Error) No meaning for identifier `Literal'. [L17 C33] #6 (Error) There are no suitable meanings for the operator `->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18: } from String; .......^ [L18 C8] #8 (Error) No meaning for identifier `String'.
The )library system command was not called after compilation.

fricas
main()
There are no library operations named main Use HyperDoc Browse or issue )what op main to learn if there is any operation containing " main " in its name.
Cannot find a no-argument definition or library operation named main .

Note: values of j and k are wrong!




  Subject:   Be Bold !!
  ( 13 subscribers )  
Please rate this page: