reset a3, kut Charlie ;)
[tt2015.git] / a3 / code / Generics / GenMap.icl
diff --git a/a3/code/Generics/GenMap.icl b/a3/code/Generics/GenMap.icl
new file mode 100644 (file)
index 0000000..6d13aa7
--- /dev/null
@@ -0,0 +1,18 @@
+implementation module GenMap\r
+\r
+import StdClass, StdArray, StdInt, StdFunc\r
+import StdGeneric, _Array\r
+\r
+generic gMap a b :: .a -> .b\r
+gMap{|c|} x                                    = x\r
+gMap{|PAIR|} fx fy (PAIR x y)  = PAIR (fx x) (fy y) \r
+gMap{|EITHER|} fl fr (LEFT x)  = LEFT (fl x)\r
+gMap{|EITHER|} fl fr (RIGHT x)         = RIGHT (fr x)\r
+gMap{|CONS|} f (CONS x)                = CONS (f x)\r
+gMap{|FIELD|} f (FIELD x)              = FIELD (f x)\r
+gMap{|OBJECT|} f (OBJECT x)    = OBJECT (f x)\r
+gMap{|{}|} f xs                                = mapArray f xs\r
+gMap{|{!}|} f xs                               = mapArray f xs\r
+\r
+derive gMap [], (,), (,,),  (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)\r
+\r