axiom-developer
[Top][All Lists]
Advanced

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

[Axiom-developer] [#209 The function |Domain| is undefined]


From: Bill Page
Subject: [Axiom-developer] [#209 The function |Domain| is undefined]
Date: Wed, 28 Sep 2005 13:32:29 -0500

Changes http://wiki.axiom-developer.org/209TheFunctionDomainIsUndefined/diff
--

++added:

This domain (renamed from AldorDomain) written in Aldor by Peter
Broadbery::

  ... can still do some useful things with them by disguising the fact
  that they are domains, so in aldor have a type

  AldorDomain: with {
        make: (T: BasicType) -> %
  } == add {
        Rep ==> T;

        make(T: BasicType): % == per T;
  }

  and your aldor programs can return this to axiom.

  Then make sure the interpreter can only see it.

  Of course, it isn't really that useful as it is - there are no
  operations on domains that are documented in aldor, so for example you
  can't say 
        "if T = Integer then ..."
  or
        "findOperation(T, add, (T, T) -> T)"

  The second is handy if you want to write a specialised interpreter, by
  the way.  In any case, you can write a domain like domain.as (see
  below).  All it does is makes sure that axiom sees an object, while
  aldor has a type to play with.  It can be extended to "know" about any
  number of domains.

  Even with these limitations, types and constructors as first class
  objects are pretty powerful.  You can build domains on the fly,
  construct functions, etc. To go further, you need a bit of reflection
  (cf the java lang.reflect stuff for where this is going). People not
  interested in axiom internals should switch off here.

Ref:

  http://lists.nongnu.org/archive/html/axiom-developer/2005-09/msg00250.html

  http://lists.nongnu.org/archive/html/axiom-developer/2005-09/msg00248.html

provides some of the missing functionality.

\begin{aldor}[aldordom]
#include "axiom.as"

Domain: BasicType with {
        make: (T: BasicType) -> %;

        theIntegerType: () -> %;
        map: (%, %) -> %;
        integerMod: PositiveInteger -> %;
        
        coerce: % -> OutputForm;

        name: % -> SExpression;

        lookup: (%, String, %) -> SExpression;

        hashCode: % -> Integer;

} == add {
        import {
                BOOT_:_:DNameToSExpr: SExpression -> SExpression;
                BOOT_:_:hashString: SExpression -> SExpression;
        } from Foreign Lisp;
        
        Rep  ==> Type;
        Rep2 ==> Record(v: Record(domType: SExpression -> SExpression, 
                                  domName: SExpression -> SExpression,
                                  notUsed: SExpression -> SExpression,
                                  lookup:  (SExpression, SExpression, 
SExpression, 
                                            SExpression, SExpression, 
SExpression,
                                            SExpression) -> SExpression,
                                  hashCode: SExpression -> SExpression,
                                  unknown: SExpression -> SExpression),
                        o: SExpression);
        
        import from Rep2;

        make(T: BasicType): % == per T;
        theIntegerType(): % == per Integer;
        integerMod(p: PositiveInteger): % == per(IntegerMod p);

        map(arg: %, ret: %): % == {
                per( (rep arg) -> (rep ret));
        }


        (a: %) = (b: %): Boolean == {
                import from Integer;
                hashCode(a) = hashCode(b)
        }


        coerce(t: %): OutputForm == {
                import from String;
                "<SomeType>"::OutputForm
        }

        name(t: %): SExpression == {
                dom := t pretend Rep2;
                axiomName((dom.v.domName)(dom.o))
        }

        -- nb: cf. interop.boot, basicLookup
        lookup(t: %, name: String, type: %): SExpression == {
                -- lookup takes the following arguments:
                -- domain rep, domain, operation, conspair, flag, lookupFn
                import from List SExpression;
                dom := t pretend Rep2;
                box: SExpression := convert [convert ""];
                lookupFn :=  dom.v.lookup;
                nil := convert [];
                lookupFn(dom.o, 
                         dom pretend SExpression, 
                         hashString(convert name), 
                         convert hashCode(type),
                         box,
                         nil, lookupFn pretend SExpression);
        }

        hashCode(t: %): Integer == {
                dom := t pretend Rep2;
                integer((dom.v.hashCode)(dom.o))
        }

        local axiomName(s: SExpression): SExpression == {
                BOOT_:_:DNameToSExpr(s);
        }

        local hashString(s: SExpression): SExpression == {
                BOOT_:_:hashString(s);
        }
}
\end{aldor}

And it nearly solves the problem!
\begin{axiom}
(Integer,Float)
\end{axiom}


--
forwarded from http://wiki.axiom-developer.org/address@hidden




reply via email to

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