axiom-developer
[Top][All Lists]
Advanced

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

Re: [Aldor-l] [Axiom-developer] spad: language and compiler


From: Ralf Hemmecke
Subject: Re: [Aldor-l] [Axiom-developer] spad: language and compiler
Date: Thu, 31 Aug 2006 12:16:54 +0200
User-agent: Thunderbird 1.5.0.5 (X11/20060719)

Probably what we need is some kind of recursive type constructor.
See for example:

http://www.cs.kent.ac.uk/people/staff/sjt/Atypical/AldorExs/vector.as

If you look closer to that, then you see that vector.as is implementing "List" in a terribly complicated way.

Look at

-- Add up the entries of a Vector(n).
addVec(n:Integer,v:Vector(n)):Integer
    == {
    import from Record(fst:Integer,rst:Vector(n-1));
    if n<=1
          then 0
          else vec.fst + addVec(n-1,vec.rst);
          where { vec == (v pretend                             -- A
                         Record(fst:Integer,rst:Vector(n-1))); }};

in particular look at the argument. If it were a list you could forget about the n, but here you have to give it. I am sure, nobody would ever use such code.

If you must have a union over Vectors of arbitrary lenght then a cleaner design would be to define vectors of lenght n and in a second step define operations on vectors of different length.

In aldor-combinat you would define that thing like in the BinaryTree example I gave before but just use the equation V = 1 + X * V.
And, by the way, I did not use "pretend" in my code.

Ralf




reply via email to

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