|
|
last edited 17 years ago |
1 | ||
Editor:
Time: 2007/11/18 17:46:20 GMT-8 |
||
Note: new |
changed: - **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. <hr /> **Bill Page wrote:** Here is a first attempt. It sort of works, but there are problems. \begin{aldor}[mm] #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 \end{aldor} \begin{axiom} )show M \end{axiom} Unfortunately the Axiom interpreter does not understand 'Tuple Type' \begin{axiom} a := m(4,"a")$M(Integer,String) \end{axiom} But this can be written in Aldor \begin{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] \end{aldor} \begin{axiom} main() \end{axiom} Note: values of j and k are wrong!
**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.
(1) -> <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 Aldor compiler and options -O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I $FRICAS/algebra Use the system command )set compiler args to change these options. "/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/mm.as",line 2: #include "axiom.as" ^ [L2 C1] #1 (Error) Could not open file `axiom.as'.
The )library system command was not called after compilation.
)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
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
#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]
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1927112369448499588-25px004.as using Aldor compiler and options -O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I $FRICAS/algebra Use the system command )set compiler args to change these options. "/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1927112369448499588-25px004.as",line 2: #include "axiom.as" ^ [L2 C1] #1 (Error) Could not open file `axiom.as'.
The )library system command was not called after compilation.
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!