--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Wed Jun 22 12:22:19 1994
--* Received: from yktvmv-ob.watson.ibm.com by asharp.watson.ibm.com (AIX 3.2/UCB 5.64/930311)
--*           id AA22609; Wed, 22 Jun 1994 12:22:19 -0400
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 8735; Wed, 22 Jun 94 12:22:20 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.BRONSTEI.NOTE.YKTVMV.9265.Jun.22.12:22:20.-0400>
--*           for asbugs@watson; Wed, 22 Jun 94 12:22:20 -0400
--* Received: from inf.ethz.ch by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Wed, 22 Jun 94 12:22:19 EDT
--* Received: from vinci.inf.ethz.ch (bronstei@vinci.inf.ethz.ch [129.132.12.46]) by inf.ethz.ch (8.6.8/8.6.6) with ESMTP id SAA25164 for <asbugs@watson.ibm.com>; Wed, 22 Jun 1994 18:22:16 +0200
--* From: Manuel Bronstein <bronstei@inf.ethz.ch>
--* Received: (bronstei@localhost) by vinci.inf.ethz.ch (8.6.8/8.6.6) id SAA17051 for asbugs@watson.ibm.com; Wed, 22 Jun 1994 18:22:16 +0200
--* Date: Wed, 22 Jun 1994 18:22:16 +0200
--* Message-Id: <199406221622.SAA17051@vinci.inf.ethz.ch>
--* To: asbugs@watson.ibm.com
--* Subject: [2] won't compile valid statement [polys.as][0.35.0]

--@ Fixed  by:  SSD   Wed Dec 7 09:28:20 EST 1994 
--@ Tested by:  none 
--@ Summary:    Type inference fixes since v0.37.0 have fixed this bug. 

------------------------ polys.as -----------------------
--
-- This won't compile, the error message complains that monomial(1,1) is
-- expanded to type SUP(R) although only SUP2(R, N) is imported:
--
-- vinci.inf.ethz.ch{bronstei} 146: asharp -M2 polys.as
-- "polys.as", line 29:         generator:% == per monomial(1, 1);
--                      ...........................^
-- [L29 C28] (Error) (After Macro Expansion) No one possible return type satisfies the context type.
--   These possible return types were rejected:
--           -- SUP(R)
--   The context requires an expression of type SUP2(R, degree$SUP(R)(p)).
-- Expanded expression was: monomial

#include "aslib.as"

macro Z == Integer;

UPC(R:Ring):Category == BasicType with {
	monomial: (R, Z) -> %;
	degree: % -> Z;
}

SUP(R:Ring):UPC(R) == add {
	macro Rep == Record(cf:R, xp:Z);
	import from {Z, R, Rep};

	sample:% == per [sample, 1];
	apply(port:OutPort, p:%):OutPort == port(rep(p).cf)("x^")(rep(p).xp);
	(p:%) = (q:%):Boolean == rep p = rep q;
	monomial(r:R, n:Z):% == per [r, n];
	degree(p:%):Z == rep(p).xp;
}

SUP2(R:Ring, n:Z):UPC(R) == SUP R;

macro N == degree(p)$SUP(R);

Foo(R:Ring, p:SUP R): BasicType with { generator: % } == SUP2(R, N) add {
	macro Rep == SUP2(R, N);
	import from {Z, R, Rep};
	generator:% == per monomial(1, 1);
}

 
