--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Sun Sep 19 02:42:53 1993
--* Received: from yktvmv2.watson.ibm.com by radical.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA26316; Sun, 19 Sep 1993 02:42:53 -0400
--* X-External-Networks: yes
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 8477; Sun, 19 Sep 93 02:47:05 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.EDWARDS.NOTE.YKTVMV.3549.Sep.19.02:47:05.-0400>
--*           for asbugs@watson; Sun, 19 Sep 93 02:47:05 -0400
--* Received: from ibm4.scri.fsu.edu by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Sun, 19 Sep 93 02:47:04 EDT
--* Received: by ibm4.scri.fsu.edu id AA12607
--*   (5.65c/IDA-1.4.4 for asbugs@watson.ibm.com); Sun, 19 Sep 1993 02:46:58 -0400
--* Date: Sun, 19 Sep 1993 02:46:58 -0400
--* From: Robert Edwards <edwards@ibm4.scri.fsu.edu>
--* Message-Id: <199309190646.AA12607@ibm4.scri.fsu.edu>
--* To: asbugs@watson.ibm.com
--* Subject: not excluding Generator(BoundedInteger(1, 4)) [bug19.as][A# version 30.4 for OSF/1 AXP]

--@ Fixed  by:  PI   Thu Jan 20 11:23:32 EST 1994 
--@ Tested by:  for0.as 
--@ Summary:    modified tibupFor 

--+ % asharp -rv bug19.as
--+ A# version 30.4 for OSF/1 AXP
--+ "bug19.as", line 132:       per [ f(i) for i:Domain in all ]
--+                       .................^
--+ [L132 C18] (Error) (After Macro Expansion) Have determined 2 possible types for th
--+ e expression.
--+         Meaning 1: Generator(BoundedInteger(1, 4))
--+         Meaning 2: Generator(Domain)
--+ Expanded expression was: for i: Domain in all
--+
--+               ld in sc sy li pa ma ab ck sb ti gf of pb pl pc po mi
--+  Time   1.0s   0  1  1  0  1  1  0  0  0  6 87  0  0  0  0  0  0  0 %
--+  Source 253L : 14016 lines per minute
-- Include a file with the basic library import
-- statements and macros.

#include "aslib"

macro
  PI == SingleInteger
  SI == SingleInteger
  NNI == SingleInteger


ReallyFinite: Category == BasicType
  with
    card: NNI
    ord:  % -> PI               -- BoundedInteger(1,card) does not work
    all:  Generator %

FiniteBasicType: Category == ReallyFinite
  with
    coerce: % -> SI
    retract: SI -> %

BoundedInteger(low: SI, high: SI): FiniteBasicType
  == SI add
    Rep ==> SI

    print("Constructing domain BoundedInteger(")(low)(",")(high)(")")()

    card: NNI == retract(high - low + 1)

    ord(a: %): PI ==
      rep(a) < low or rep(a) > high =>
        error "BoundedInteger: ord out of range"
      retract(rep(a) - low + 1)

    macro Coerce X == X
--  macro Coerce X == coerce(X)

    coerce(a: %): SI == rep a

    retract(a: SI): % ==
      a < low or a > high =>
        error "BoundedInteger: ord of coerce out of range"
      per a

    all: Generator % == generate
      a := low
      while a <= high repeat
        yield per a
        a := a + 1

import String

MapDefault ==>
    sample: % ==
      import String
--    error "Default `sample' not implemented"
      print("Calling sample")()
      nil$Pointer pretend %

    (a: %) = (b: %): Boolean ==
      import String
      error "Default `=' not implemented"
      true

    (a: %) ~= (b: %): Boolean ==
      import String
      error "Default `=' not implemented"
      false

+++ `Map' is the category of mappings (i.e., the domain of objects and
+++ morphisms in categorical terms)
+++
+++ Author: ADK
+++ Date Created: 26-JUL-1993 17:56:55.00
+++ Axioms:
+++   apply(coerce(f),x) = f(x)  for all x: Domain, and f: Domain -> Codomain

Map(Domain: BasicType, Codomain: BasicType): Category == BasicType
  with
    apply: (%, Domain) -> Codomain	++ function evaluation
    coerce: (Domain -> Codomain) -> %	++ constructor (make less lazy)
    coerce: % -> (Domain -> Codomain)   ++ constructor (make more lazy)

-------------------------------------------------------------------------------

+++ `FunctionMap' is a domain of lazy maps (lambda expressions)
+++
+++ Author: ADK
+++ Date Created: 26-JUL-1993 18:31:18.00

FunctionMap(Domain: BasicType, Codomain: BasicType): Map(Domain, Codomain) ==
  add
    Rep ==> Domain -> Codomain
    import Rep

    print("Constructing domain FunctionMap")()

    MapDefault   -- compiler bug evasion

    apply(p: OutPort, a: %): OutPort ==
      import String
      p("Not implemented")()

    apply(f: %, d: Domain): Codomain == (rep f)(d)
    coerce(f: Rep): % ==
      print("FunctionMap: coerce:Rep -> %")()
      per f
    coerce(f: %): Rep == rep f

+++ `ArrayMap' is a domain of non-lazy maps from BoundedInteger
+++
+++ Author: ADK
+++ Date Created: 26-JUL-1993 18:31:18.00

ArrayMap(Domain: ReallyFinite, Codomain: BasicType): Map(Domain, Codomain) ==
  add
    Rep ==> Array(Codomain)
    import Rep

    print("Constructing domain ArrayMap")()

    MapDefault   -- compiler bug evasion

    apply(p: OutPort, a: %): OutPort ==
      import String
      p((rep a))(" :: ArrayMap")()

    apply(f: %, d: Domain): Codomain == apply(rep f,ord d)

    coerce(f: Domain -> Codomain): % ==
      per [ f(i) for i:Domain in all ]
--      per [ f(i) for i:Domain in all$Domain ]

    coerce(a: %): Domain -> Codomain ==
      (i: Domain): Codomain +-> apply(a,i)

print("Start test...")()

import SI

--BI: FiniteBasicType == BoundedInteger(1,4)
macro BI == BoundedInteger(1,4)

import BI

l: ArrayMap(BI,SI) == coerce( (x: BI): SI +-> 10 * coerce(x)@SI ) @ ArrayMap(BI,SI)

--print("l(3) = ")(l(val 3))()
 
