--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Fri Aug  5 13:46:48 1994
--* Received: from yktvmv-ob.watson.ibm.com by asharp.watson.ibm.com (AIX 3.2/UCB 5.64/930311)
--*           id AA22500; Fri, 5 Aug 1994 13:46:48 -0400
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 3125; Fri, 05 Aug 94 13:46:52 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.LAL.NOTE.YKTVMV.6841.Aug.05.13:46:51.-0400>
--*           for asbugs@watson; Fri, 05 Aug 94 13:46:51 -0400
--* Received: from nag.com by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Fri, 05 Aug 94 13:46:48 EDT
--* Received: by nag.com (/\==/\ Smail3.1.28.1 #28.1)
--* 	id <m0qWTMy-0001XtC@nag.com>; Fri, 5 Aug 94 12:47 CDT
--* Message-Id: <m0qWTMy-0001XtC@nag.com>
--* Date: Fri, 5 Aug 94 12:47 CDT
--* From: lal@nag.com (Larry A. Lambe)
--* To: asbugs@watson.ibm.com, lal@nag.com
--* Subject: [3] missed msg (now you seeit, now you don't) [test1.as][36.1 (suncc)]

--@ Fixed  by:  SSD   Tue Aug 9 11:05:15 EDT 1994 
--@ Tested by:  none 
--@ Summary:    Uses of ids in types were not being propagated to outer scopes. 

--+ -- this is an example which was gibven to me by a colleague in
--+ -- Stockholm.  It really concerns compiler error messages.  I
--+ -- believe that the code below is incorrect for two reasons.
--+ -- 1.) there is an assignment Rep := SI and as Stephen explained
--+ --     to me over the phone the other day, since Rep is used in a
--+ --     type it must be constant and so cannot be assigned to.
--+ --
--+ -- 2.) ExponentCategory is also an abelain group and so there
--+ --     should be something like "import from SI" in the body.
--+ --     Is that right?
--+ --
--+ -- The example continues following the listing and the result of
--+ -- a run:
--+ --
--+
--+ =================================================
--+
--+ #include "aslib"
--+
--+ #library PolyCat "polycat.aso";
--+ import from   PolyCat;
--+ #library Poly "poly.aso";
--+ import from Poly;
--+
--+
--+ import from SingleInteger;
--+ SI ==> SingleInteger;
--+
--+ SingleExponent : ExponentCategory with { coerce: SI -> % }
--+ == SI add {
--+     Rep := SI;
--+     sup(x:%,y:%):% == per(max(rep x,rep y)$Rep);
--+     nonNegative?(x:%) : Boolean == rep(x) >=$Rep 0$Rep;
--+     coerce(x : SI) : % == x @ SI pretend %;
--+     sum(x : %) : SI == x @ % pretend SI;
--+ }
--+
--+
--+ import from SingleExponent;
--+ SE ==> SingleExponent;
--+ import from Integer;
--+ INT ==> Integer;
--+ import from  Polynomial(INT,SE);
--+ POL ==> Polynomial(INT,SE);
--+
--+ t : POL := monomial(1,1::SE);
--+
--+ =========================================
--+
--+ fruit% asharp -G run -lasdem teke2.as
--+ sh: 16565 Memory fault - core dumped
--+
--+ =========================================
--+
--+ --  Now I show two files, test1.as and test2.as.  In test1.as,
--+ --  I drop the last 11 lines and the compiler does not complain
--+ --  and the code runs:
--+
--+ =====================================================
--+ -- test1.as
--+ #include "aslib"
--+
--+ #library PolyCat "polycat.aso";
--+ import from   PolyCat;
--+ #library Poly "poly.aso";
--+ import from Poly;
--+
--+ import from SingleInteger;
--+ SI ==> SingleInteger;
--+
--+ SingleExponent : ExponentCategory with { coerce: SI -> % }
--+ == SI add {
--+     Rep := SI;
--+     sup(x:%,y:%):% == per(max(rep x,rep y)$Rep);
--+     nonNegative?(x:%) : Boolean == rep(x) >=$Rep 0$Rep;
--+     coerce(x : SI) : % == x @ SI pretend %;
--+     sum(x : %) : SI == x @ % pretend SI;
--+ }
--+
--+ =========================================
--+
--+ fruit% asharp -G run -lasdem test1.as
--+
--+ =========================================
--+
--+ -- I now add the line to import from Rep and the
--+ -- compiler now sees the assignment error!
--+ --
--+ =======================================
--+
--+ -- test2.as
--+ #include "aslib"
--+
--+ #library PolyCat "polycat.aso";
--+ import from   PolyCat;
--+ #library Poly "poly.aso";
--+ import from Poly;
--+
--+ import from SingleInteger;
--+ SI ==> SingleInteger;
--+
--+ SingleExponent : ExponentCategory with { coerce: SI -> % }
--+ == SI add {
--+     Rep := SI;
--+     import from Rep;
--+     sup(x:%,y:%):% == per(max(rep x,rep y)$Rep);
--+     nonNegative?(x:%) : Boolean == rep(x) >=$Rep 0$Rep;
--+     coerce(x : SI) : % == x @ SI pretend %;
--+     sum(x : %) : SI == x @ % pretend SI;
--+ }
--+
--+ =======================================
--+
--+ fruit% asharp -G run -lasdem test2.as
--+ "test2.as", line 13:     Rep := SI;
--+                      ....^
--+ [L13 C5] #1 (Error) `Rep' is used in a type, so must be constant, and so cannot be assigned to.
--+
--+ =======================================
--+
--+ -- Finally, I change the assignment to a macro, omit the import line
--+ -- and give back the last 11 lines and add a print statement:
--+
--+ -- test3.as
--+ #include "aslib"
--+
--+ #library PolyCat "polycat.aso";
--+ import from   PolyCat;
--+ #library Poly "poly.aso";
--+ import from Poly;
--+
--+
--+ import from SingleInteger;
--+ SI ==> SingleInteger;
--+
--+ SingleExponent : ExponentCategory with { coerce: SI -> % }
--+ == SI add {
--+     Rep ==> SI;
--+     sup(x:%,y:%):% == per(max(rep x,rep y)$Rep);
--+     nonNegative?(x:%) : Boolean == rep(x) >=$Rep 0$Rep;
--+     coerce(x : SI) : % == x @ SI pretend %;
--+     sum(x : %) : SI == x @ % pretend SI;
--+ }
--+
--+
--+ import from SingleExponent;
--+ SE ==> SingleExponent;
--+ import from Integer;
--+ INT ==> Integer;
--+ import from  Polynomial(INT,SE);
--+ POL ==> Polynomial(INT,SE);
--+
--+ t : POL := monomial(1,1::SE);
--+
--+ print << t << newline;
--+
--+ =============================================
--+
--+ -- It compiles and executes without complaint.
--+
--+ ===============================================
--+
--+ fruit% asharp -G run -lasdem test3.as
--+ X^1
--+ ===============================================
#include "aslib"

#library PolyCat "polycat.aso";
import from   PolyCat;
#library Poly "poly.aso";
import from Poly;

import from SingleInteger;
SI ==> SingleInteger;

SingleExponent : ExponentCategory with { coerce: SI -> % }
== SI add {
    Rep := SI;
    sup(x:%,y:%):% == per(max(rep x,rep y)$Rep);
    nonNegative?(x:%) : Boolean == rep(x) >=$Rep 0$Rep;
    coerce(x : SI) : % == x @ SI pretend %;
    sum(x : %) : SI == x @ % pretend SI;
}

 
