axiom-developer
[Top][All Lists]
Advanced

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

Re: [Axiom-developer] Problem kTuple wish 2.


From: Ralf Hemmecke
Subject: Re: [Axiom-developer] Problem kTuple wish 2.
Date: Thu, 05 Jul 2007 12:03:18 +0200
User-agent: Thunderbird 2.0.0.4 (X11/20070604)

http://wiki.axiom-developer.org/SandBoxAldorTuples

Thank you, Bill. I think, I love the idea with

  get: % -> T

But that is only a tiny bit and actually does not solve the problem that I finally would like to return something like

(F Integer, F String)

for some domain constructor F if the input T is (Integer,String).

The code compiles and is apparently type correct but it does not
exactly produce the expected output. This code seems to work best
compiled to Lisp and iinked into Axiom. When I try the same thing with
the Aldor stand alone compiler I get some peculiar and unexpected
error messages. Perhaps this is pushing the limits of what the
compiler can do but I seems to be almost there... Perhaps a bug report
is in order?

To make that error message clearer I realized to following:

woodpecker:~/scratch>aldor -fx -laldor aaa.as
woodpecker:~/scratch>aaa
Looking in M((AldorInteger, String)) for m with code 111396431
Unhandled Exception: RuntimeError()
Export not found

for the program given below. To me that looks like a compiler bug.

To be honest, I am not sure whether the compiler should actually compile that code without complaint.

If one writes

  m(4, "a)                             (*)

then what is

  (4, "a")                             (**)

? A multi-value. But m cannot be applied to multivalues. It needs a tuple.

Maybe the compiler applies courtesy conversions???
http://www.aldor.org/docs/HTML/chap7.html

If (**) is a tuple, then what is its type? Since we want it to be a tuple, it must be

  Tuple SOMETHING

. Well, now we have a problem to get SOMETHING from Integer and String.
Union(Integer, String) would work. But that looks totally ugly and would allow (4, 4711) instead of (4, "a").

Now the only thing that comes to my mind would be to use Cross instead of Tuple. But writing

extend Cross(T: Tuple Type): with {...} == add {...}

instead of

M(T: Tuple Type): with {...} == add {...}

and then

  import from Cross(Integer, String).

gives the same problems.

Ralf

---BEGIN aaa.as
#include "aldor"
#include "aldorio"

M(T: Tuple Type): with {
    m: T -> %;
    get: % -> T;
} == add {
    m(x:T):% == (x) pretend %;
    get(x:%):T == x pretend T;
}

main(): () == {
        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)
        --
        (x, y) := get(a);
        stdout << "(x,y) = (" << x << "," << y << ")" << newline;

        (i,j,k) := get(b);
        stdout << "(i,j,k) = (" << i << "," << j << "," << k << ")" << newline;
}
main();
---END aaa.as




reply via email to

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