--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Wed Nov  3 06:24:48 1993
--* Received: from yktvmv.watson.ibm.com by radical.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA13869; Wed, 3 Nov 1993 06:24:48 -0500
--* X-External-Networks: yes
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 6863; Wed, 03 Nov 93 06:31:59 EST
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.BRONSTEI.NOTE.YKTVMV.7983.Nov.03.06:31:58.-0500>
--*           for asbugs@watson; Wed, 03 Nov 93 06:31:59 -0500
--* Received: from bernina.ethz.ch by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Wed, 03 Nov 93 06:31:58 EST
--* Received: from neptune by bernina.ethz.ch with SMTP inbound id <15614-0@bernina.ethz.ch>; Wed, 3 Nov 1993 12:31:49 +0100
--* From: Manuel Bronstein <bronstei@inf.ethz.ch>
--* Received: from rutishauser.inf.ethz.ch (rutishauser-gw.inf.ethz.ch) by neptune id AA27396; Wed, 3 Nov 93 12:31:46 +0100
--* Date: Wed, 3 Nov 93 12:31:44 +0100
--* Message-Id: <9311031131.AA09848@rutishauser.inf.ethz.ch>
--* Received: from vinci.inf.ethz.ch.rutishauser by rutishauser.inf.ethz.ch id AA09848; Wed, 3 Nov 93 12:31:44 +0100
--* To: asbugs@watson.ibm.com
--* Subject: formal parameter name in category doesn't get replaced by actual parameter [minisup.as][32.0  RS/6000]

--@ Fixed  by:  SMW   Wed Nov 24 21:12:10 EST 1993 
--@ Tested by:  ? 
--@ Summary:    Repaired by recent round of enhancements. 

#include "aslib.as"

CommutativeRing:Category == Ring

Module(R:CommutativeRing): Category == Ring with {
	*: (R, %) -> %;
	*: (%, R) -> %
}

Algebra(R:CommutativeRing): Category == Module R with {
        coerce: R -> %;
        default coerce(r:R):% == r * 1
}

macro Z == Integer

-- this compiles if Algebra F is replaced by Module F
-- but not with Algebra F
MiniPoly(F:CommutativeRing): Algebra F == add {
	Term: BasicType with {
		term: (F, Z) -> %;    -- term(c, n) creates the monomial c x^n
		coef: % -> F;         -- coef(c x^n) returns c
		expt: % -> Z;         -- expt(c x^n) returns n
	} == add {
		macro Rep == Record(coef:F, expt:Z);
		import Rep;
		term(c:F, n:Z):% == per [c, n];
		coef(t:%):F      == rep(t).coef;
		expt(t:%):Z      == rep(t).expt;

		-- Made the domain a basic type to pass it to List (SMW).
		sample: %        == nil$Pointer pretend %;
		(a: %) = (b: %): Boolean == coef a = coef b and expt a = expt b;
		apply(p: OutPort, t: %): OutPort == p;
	}
	macro Rep == List Term;
	import Term;
	import Rep;
	import F;
	import Z;

	0:%                       == per empty();
	1:%                       == per list term(1, 0);
	(x:%) = (y:%):Boolean     == rep x = rep y;

    -- the following are all mathematically incorrect, but who cares?
	(c:F) * (p:%):% == p;
  	(p:%) * (c:F):% == p;
	(x:%) * (y:%):% == x;
	(x:%) + (y:%):% == x;
	(x:%) - (y:%):% == x;
	-(p:%):%        == p;

	apply(p: OutPort, x: %): OutPort == p;  -- (Added SMW)
}
 
