--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Mon Aug  1 16:39:59 1994
--* Received: from yktvmv-ob.watson.ibm.com by asharp.watson.ibm.com (AIX 3.2/UCB 5.64/930311)
--*           id AA15248; Mon, 1 Aug 1994 16:39:59 -0400
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 3021; Mon, 01 Aug 94 16:39:42 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.LAL.NOTE.YKTVMV.9173.Aug.01.16:39:42.-0400>
--*           for asbugs@watson; Mon, 01 Aug 94 16:39:42 -0400
--* Received: from nag.com by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Mon, 01 Aug 94 16:39:26 EDT
--* Received: by nag.com (/\==/\ Smail3.1.28.1 #28.1)
--* 	id <m0qV49d-0001XtC@nag.com>; Mon, 1 Aug 94 15:40 CDT
--* Message-Id: <m0qV49d-0001XtC@nag.com>
--* Date: Mon, 1 Aug 94 15:40 CDT
--* From: lal@nag.com (Larry A. Lambe)
--* To: asbugs@watson.ibm.com, lal@nag.com
--* Subject: [3] missing library code??? [ex18.as][36.1 (suncc)]

--@ Fixed  by:  SSD   Tue Aug 2 09:03:45 EDT 1994 
--@ Tested by:  none 
--@ Summary:    ex18.as updated to correspond to v36. 

--+ NOTE:  I have tried compiling with a combination of other libraries as well,
--+ but get the same result.  I also looked in the samples dir through the source
--+ code for the libraries in version 36.1, but could not find any reference to
--+ GcdDomain.  Is there something missing?
--+
--+ ===================================================
--+
--+ fruit% asharp -Fx -lasdem ex18.as
--+ "ex18.as", line 7: SimplePoly(R: GcdDomain):
--+                    ..............^
--+ [L7 C15] #2 (Error) No meaning for identifier `GcdDomain'.
--+
--+ "ex18.as", line 8:         Join(PolynomialCategory(R, Integer), Applicable R)
--+                    .............^
--+ [L8 C14] #3 (Error) There are no suitable meanings for the operator `PolynomialCategory'.
--+
--+ "ex18.as", line 10:         import from R;
--+                     ....................^
--+ [L10 C21] #7 (Error) There are 0 meanings for `R' in this context.
--+ The possible types were:
--+           R: GcdDomain, a local
--+   The context requires an expression of type Tuple(Type).
--+
--+ "ex18.as", line 19:         apply(p: %, e: R) : R == {
--+                     .......................^
--+ [L19 C24] #10 (Error) There are 0 meanings for `R' in this context.
--+ The possible types were:
--+           R: GcdDomain, a local
--+   The context requires an expression of type Tuple(Type).
--+
--+ "ex18.as", line 39:         print << (x2p1 2);
--+                     ........^
--+ [L39 C9] #1 (Warning) Suspicious juxtaposition.  Check for missing `;'.
--+ Check indentation if you are using `#pile'.
--+ [L39 C9] #12 (Fatal Error) Too many errors (use `-M emax=n' or `-M no-emax' to change the limit).
--+
-- Example 18.  Polynomial Evaluation

#include "aslib"

Applicable(R: BasicType): Category == with { apply: (%, R) -> R };

SimplePoly(R: GcdDomain):
        Join(PolynomialCategory(R, Integer), Applicable R)
== Polynomial(R, Integer) add {
        import from R;
        import from Integer;

        (x: R) ^ (n: Integer): R == {
                n = 0  => 1;
                odd? n => x * (x ^ (n-1));
                (x * x) ^ (n quo 2)
        }

        apply(p: %, e: R) : R == {
                poly := p;
                val : R := 0;
                while (degree poly > 0) repeat {
                        mon := leadingCoefficient(p)*(e^degree poly);
                        val := val + mon;
                        poly := reductum poly;
                }
                val + leadingCoefficient poly;
        }
}

T1(): () == {
        import from SimplePoly(Integer), Integer;

        x: SimplePoly Integer := monomial(1,1);

        x2p1: SimplePoly Integer := (x*x) + 1;

        print x2p1 << newline
        print << (x2p1 2);
}

T1();
 
