--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Tue Nov 22 08:38:20 1994
--* Received: from yktvmv-ob.watson.ibm.com by asharp.watson.ibm.com (AIX 3.2/UCB 5.64/930311)
--*           id AA24311; Tue, 22 Nov 1994 08:38:20 -0500
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 3089; Tue, 22 Nov 94 08:38:26 EST
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.HEMMECKE.NOTE.YKTVMV.6675.Nov.22.08:38:26.-0500>
--*           for asbugs@watson; Tue, 22 Nov 94 08:38:26 -0500
--* Received: from server1.rz.uni-leipzig.de by watson.ibm.com (IBM VM SMTP V2R3)
--*    with TCP; Tue, 22 Nov 94 08:34:52 EST
--* Received: from aix550.informatik.uni-leipzig.de by server1.rz.uni-leipzig.de with SMTP
--* 	(1.38.193.5/15.6) id AA19153; Tue, 22 Nov 1994 14:32:37 +0100
--* Received: by aix550.informatik.uni-leipzig.de (AIX 3.2/UCB 5.64/BelWue-1.1AIXRS)
--*           id AA13662; Tue, 22 Nov 1994 14:32:54 +0100
--* Date: Tue, 22 Nov 1994 14:32:54 +0100
--* From: hemmecke@aix550.informatik.uni-leipzig.de (Ralf Hemmecke)
--* Message-Id: <9411221332.AA13662@aix550.informatik.uni-leipzig.de>
--* To: asbugs@watson.ibm.com
--* Subject: [3] problems with extend

--@ Fixed  by:  SSD   Wed Nov 23 09:43:10 EST 1994 
--@ Tested by:  none 
--@ Summary:    Various type inference fixes since v0-37-0 have fixed this bug. 

-- Command line: asharp -gloop -DC1
-- Version: A# version 0.36.5 for AIX RS/6000
-- Original bug file name: xxx.as

------------ example file --- cut here --------------------------------------
-- Author: Ralf Hemmecke, University of Leipzig
-- Date: 21-NOV-94
-- A# version 0.36.5 for AIX RS/6000

-- The following code demonstrates a problem when using the extend keyword.
-- The names of categories and domains could be misleading but I hope I have
-- cut down the code short enough to concentrate on this strange error
-- message (see below).
-- If all the following is simply a misunderstanding on my part how to
-- use "extend", would you please send me a few more word about extentions
-- than I can read in the A# User's Guide.
--------------------------------------------------------------------
-- For explanation how to use this file, see at the bottom.
--------------------------------------------------------------------
#include "aslib"

macro Cat == AbelianMonoid with { foo: (%,%) -> % };
--------------------------------------------------------------------
extend Integer: Cat == add {
#if C1
  foo(x:%,y:%): % == x-y;
#elseif C2
  foo(x:%,y:%): % == x;
#endif
}
--------------------------------------------------------------------
NonNegativeInteger: Join(EuclideanDomain,Cat) with == Integer add;
--------------------------------------------------------------------
define DirectProductCategory(S:Cat): Category == AbelianMonoid with;

DirectProduct(dim:SingleInteger,S:Cat): DirectProductCategory S == add {
  Rep ==> Array S;
  import from Rep,S;
  0: % == per new(dim,0$S);
  zero?(v:%):Boolean == v = 0;
  (v1: %) =  (v2: %): Boolean == rep(v1) = rep(v2);
  (v1: %) ~= (v2: %): Boolean == rep(v1) ~= rep(v2);
  (v1: %) + (v2: %): % == v1;
  +(v: %): %           == v;

  (p: TextWriter) << (v: %): TextWriter == {
    dim=0 => p << "()";
    p << "(" << rep(v).1;
    for i in 2..dim repeat p  << "," << rep(v).i;
    p << ")"
  }
}
---------------------------------------------------------------------------
-- The following 5 lines help to shorten the input by hand.
macro {
  DI == DirectProduct(numOfVars,Integer);
  DN == DirectProduct(numOfVars,NonNegativeInteger);
}
numOfVars:SingleInteger == 3;

---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- HOW TO USE
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- This code should be used in interactive mode , i.e., with asharp -gloop.
-- There are two possible options.
-- 1) asharp -gloop -DC1
-- 2) asharp -gloop -DC2
--
-- At the A# prompt load the file via
--	#include "xxx.as"
-- then input
--	0$DI
-- and
--	0$DN
--
-- When using option C2 the output is
--	(0,0,0) @ DirectProduct(numOfVars, Integer)
-- and
--	(0,0,0) @ DirectProduct(numOfVars, NonNegativeInteger)
-- as one would expect.
-- However, with C1 the input 0$DI works as well but 0$DN gives the folloing
-- error message:

--:Looking in Integer for = with code 257326914
--:Export not found
--:#0 20095780 in <domainGetExport!> at unit [runtime]
--:#1     1eae in <BasicType> at unit [ascat]
--:#2     554d in <get0> at unit [runtime]
--:#3     29af in <get> at unit [runtime]
--:#4     6467 in <domainGetExport!> at unit [runtime]
--:#5     5ee4 in <AbelianMonoid> at unit [ascat]
--:#6     554d in <get0> at unit [runtime]
--:#7     291b in <get> at unit [runtime]
--:#8     6467 in <domainGetExport!> at unit [runtime]
--:#9      29b in <addLevel1> at unit [top-level]
--:#10     405c in <get> at unit [runtime]
--:#11     4638 in <getExtend> at unit [runtime]
--:#12     34f8 in <get> at unit [runtime]
--:#13     726e in <lazyForceImport> at unit [runtime]
--:#14     1836 in <addLevel1> at unit [top-level]
--:#15     405c in <get> at unit [runtime]
--:#16     726e in <lazyForceImport> at unit [runtime]
--:#17       e9 in <-> at unit [main]
--:#18        0 in <-> at unit [main]
--:...
--: @ DirectProduct(numOfVars, NonNegativeInteger)

-- After the commands
--	import from DN;
--	0$DN
-- one will see the following:

--:Looking in DirectProduct(dim==<value>, NonNegativeInteger) for 0 with code
--:488094542
--:Export not found
--:#0 200920d0 in <domainGetExport!> at unit [runtime]
--:#1     5ee4 in <AbelianMonoid> at unit [ascat]
--:#2     554d in <get0> at unit [runtime]
--:#3     291b in <get> at unit [runtime]
--:#4     72a2 in <lazyForceImport> at unit [runtime]
--:#5       e9 in <-> at unit [main]
--:#6        0 in <-> at unit [main]
--:...
--: @ DirectProduct(numOfVars, NonNegativeInteger)

-- Entering the same commands again, i.e.,
--      import from DN;
--      0$DN
-- will give the following:

--:Looking in DirectProduct(dim==<value>, NonNegativeInteger) for 0 with code
--:488094542
--:Export not found
--:#0 200911d0 in <lazyForceImport> at unit [runtime]
--:#1       e9 in <-> at unit [main]
--:#2        0 in <-> at unit [main]
--:...
--: @ DirectProduct(numOfVars, NonNegativeInteger)
------------ end of example file --- cut here ----------------------------
 
