109843d8b3dd4cc7939b09f2576598772de7115b
[tt2015.git] / a3 / code / Generics / GenMapSt.icl
1 implementation module GenMapSt
2
3 import StdGeneric, _Array
4
5 derive bimap (,)
6
7 generic gMapLSt a b :: .a .st -> (.b, .st)
8 gMapLSt{|c|} x st = (x, st)
9 gMapLSt{|PAIR|} fx fy (PAIR x y) st
10 # (x, st) = fx x st
11 # (y, st) = fy y st
12 = (PAIR x y, st)
13 gMapLSt{|EITHER|} fl fr x st = mapStEITHER fl fr x st
14 gMapLSt{|CONS|} f x st = mapStCONS f x st
15 gMapLSt{|FIELD|} f x st = mapStFIELD f x st
16 gMapLSt{|OBJECT|} f x st = mapStOBJECT f x st
17 gMapLSt{|{}|} f x st = mapArrayLSt f x st
18 gMapLSt{|{!}|} f x st = mapArrayLSt f x st
19
20 derive gMapLSt [], (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
21
22 generic gMapRSt a b :: .a .st -> (.b, .st)
23 gMapRSt{|c|} x st = (x, st)
24 gMapRSt{|PAIR|} fx fy (PAIR x y) st
25 # (y, st) = fy y st
26 # (x, st) = fx x st
27 = (PAIR x y, st)
28 gMapRSt{|EITHER|} fx fy x st = mapStEITHER fx fy x st
29 gMapRSt{|CONS|} f x st = mapStCONS f x st
30 gMapRSt{|FIELD|} f x st = mapStFIELD f x st
31 gMapRSt{|OBJECT|} f x st = mapStOBJECT f x st
32 gMapRSt{|{}|} f x st = mapArrayRSt f x st
33 gMapRSt{|{!}|} f x st = mapArrayRSt f x st
34
35 derive gMapRSt [], (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
36
37
38 mapStEITHER fl fr (LEFT x) st
39 # (x, st) = fl x st
40 = (LEFT x, st)
41 mapStEITHER fl fr (RIGHT x) st
42 # (x, st) = fr x st
43 = (RIGHT x, st)
44 mapStCONS f (CONS x) st
45 # (x, st) = f x st
46 = (CONS x, st)
47 mapStFIELD f (FIELD x) st
48 # (x, st) = f x st
49 = (FIELD x, st)
50 mapStOBJECT f (OBJECT x) st
51 # (x, st) = f x st
52 = (OBJECT x, st)
53