reset a3, kut Charlie ;)
[tt2015.git] / a3 / code / Generics / GenHylo.icl
diff --git a/a3/code/Generics/GenHylo.icl b/a3/code/Generics/GenHylo.icl
new file mode 100644 (file)
index 0000000..d8e5876
--- /dev/null
@@ -0,0 +1,18 @@
+implementation module GenHylo \r
+\r
+import StdGeneric, GenMap, StdFunc\r
+\r
+:: Fix f = In (f .(Fix f))\r
+\r
+Out :: !u:(Fix v:a) -> v:(a w:(Fix v:a)), [u <= w]\r
+Out (In x) = x\r
+\r
+hylo :: ((.f .b) -> .b) (.a -> (.f .a)) -> (.a -> .b) | gMap{|*->*|} f\r
+hylo consume produce = consume o gMap{|*->*|} (hylo consume produce) o produce\r
+\r
+cata :: (u:(f .a) -> .a) -> (Fix u:f) -> .a | gMap{|*->*|} f\r
+cata f = hylo f Out \r
+\r
+ana :: (.a -> u:(f .a)) -> .a -> (Fix u:f) | gMap{|*->*|} f\r
+ana f = hylo In f\r
+\r