d8e58760760f8a937d0db6423864dd1b09df099f
[tt2015.git] / a3 / code / Generics / GenHylo.icl
1 implementation module GenHylo
2
3 import StdGeneric, GenMap, StdFunc
4
5 :: Fix f = In (f .(Fix f))
6
7 Out :: !u:(Fix v:a) -> v:(a w:(Fix v:a)), [u <= w]
8 Out (In x) = x
9
10 hylo :: ((.f .b) -> .b) (.a -> (.f .a)) -> (.a -> .b) | gMap{|*->*|} f
11 hylo consume produce = consume o gMap{|*->*|} (hylo consume produce) o produce
12
13 cata :: (u:(f .a) -> .a) -> (Fix u:f) -> .a | gMap{|*->*|} f
14 cata f = hylo f Out
15
16 ana :: (.a -> u:(f .a)) -> .a -> (Fix u:f) | gMap{|*->*|} f
17 ana f = hylo In f
18