--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Mon Jul 12 17:42:50 1993
--* Received: from yktvmv2.watson.ibm.com by radical.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA14811; Mon, 12 Jul 1993 17:42:50 -0400
--* X-External-Networks: yes
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 4563; Mon, 12 Jul 93 17:43:50 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.ADK.NOTE.YKTVMV.6315.Jul.12.17:43:48.-0400>
--*           for asbugs@watson; Mon, 12 Jul 93 17:43:50 -0400
--* Received: from ibm4.scri.fsu.edu by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Mon, 12 Jul 93 17:43:47 EDT
--* Received: by ibm4.scri.fsu.edu id AA26888
--*   (5.65c/IDA-1.4.4 for asbugs@watson.ibm.com); Mon, 12 Jul 1993 17:43:41 -0400
--* Date: Mon, 12 Jul 1993 17:43:41 -0400
--* From: Tony Kennedy <adk@ibm4.scri.fsu.edu>
--* Message-Id: <199307122143.AA26888@ibm4.scri.fsu.edu>
--* To: asbugs@watson.ibm.com
--* Subject: swap.as doesn't compile! [/ds13/m/users/edwards/applications/asharp/base/rs3.2/samples/swap.as][A# version 28.I for AIX RS/6000 (debug version)]

--@ Fixed  by: SSD Fri Jul 16 18:34:32 1993
--@ Tested by: swap.as
--@ Summary:   swap.as compiles in v29.2

--> testcomp
--> testrun

#include "aslib.as"

Ag ==> (S: BasicType) -> Aggregate S

-- This function takes two type constructors as arguments
-- and produces a new function to swap aggregate data
-- structure layers.

swap(X:Ag,Y:Ag)(S:BasicType)(x:X Y S):Y X S ==
        [[s for s: S in y]$X(S) for y: Y S in x]$Y(X(S))

-- Now we import those domains we will use.

import List  Integer
import Array Integer
import Integer
import Segment Integer
import String

-- Let's try to swap list and array levels.

al: Array List Integer :=
        array(list(i+j-1 for i in 1..3) for j in 1..3)

print("This is an array of lists: ")()(al)()()

la: List Array Integer := swap(Array,List)(Integer)(al)

print("This is a list of arrays: ")()(la)()
 
