comparison eq.ur @ 6:799f43bce62b

Import some code from iwl
author Adam Chlipala <adam@chlipala.net>
date Tue, 14 Dec 2010 10:33:24 -0500
parents
children 744bf911dcc6
comparison
equal deleted inserted replaced
5:943410267fad 6:799f43bce62b
1 con eq = K ==> fn (t1 :: K) (t2 :: K) => f :: (K -> Type) -> f t1 -> f t2
2
3 val refl [K] [t ::: K] : eq t t = fn [f :: (K -> Type)] x => x
4
5 fun sym [K] [t1 ::: K] [t2 ::: K] (e : eq t1 t2) : eq t2 t1 =
6 e [fn t => eq t t1] refl
7
8 fun trans [K] [t1 ::: K] [t2 ::: K] [t3 ::: K] (e1 : eq t1 t2) (e2 : eq t2 t3) : eq t1 t3 =
9 (sym e1) [fn t => eq t t3] e2
10
11 fun cast [K] [t1 ::: K] [t2 ::: K] (e : eq t1 t2) = e
12
13 fun fold [K] [tf :: {K} -> Type] [r ::: {K}]
14 (f : pre :: {K} -> nm :: Name -> v :: K -> post :: {K} -> [pre ~ post] => [[nm] ~ pre ++ post] =>
15 eq r (pre ++ [nm = v] ++ post) -> tf post -> tf ([nm = v] ++ post))
16 (i : tf []) (fl : folder r) : tf r =
17 @@Top.fold [fn post => pre :: {K} -> [pre ~ post] => eq r (pre ++ post) -> tf post]
18 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
19 (acc : pre :: {K} -> [pre ~ rest] => eq r (pre ++ rest) -> tf rest)
20 [pre :: {K}] [pre ~ [nm = t] ++ rest] pf =>
21 f [pre] [nm] [t] [rest] ! ! pf (acc [[nm = t] ++ pre] ! pf))
22 (fn [pre :: {K}] [pre ~ []] _ => i) [r] fl [[]] ! refl
23
24 fun foldUR [tr :: Type] [tf :: {Unit} -> Type] [r ::: {Unit}]
25 (f : pre :: {Unit} -> nm :: Name -> post :: {Unit} -> [pre ~ post] => [[nm] ~ pre ++ post] =>
26 eq r (pre ++ [nm] ++ post) -> tr -> tf post -> tf ([nm] ++ post))
27 (i : tf []) (fl : folder r) (r : $(mapU tr r)) : tf r =
28 @@fold [fn r' => $(mapU tr r') -> tf r'] [r]
29 (fn [pre :: {Unit}] [nm :: Name] [u :: Unit] [post :: {Unit}] [pre ~ post] [[nm] ~ pre ++ post] pf acc r =>
30 f [pre] [nm] [post] ! ! pf r.nm (acc (r -- nm)))
31 (fn _ => i) fl r
32
33 fun foldR [K] [tr :: K -> Type] [tf :: {K} -> Type] [r ::: {K}]
34 (f : pre :: {K} -> nm :: Name -> t :: K -> post :: {K} -> [pre ~ post] => [[nm] ~ pre ++ post] =>
35 eq r (pre ++ [nm = t] ++ post) -> tr t -> tf post -> tf ([nm = t] ++ post))
36 (i : tf []) (fl : folder r) (r : $(map tr r)) : tf r =
37 @@fold [fn r' => $(map tr r') -> tf r'] [r]
38 (fn [pre :: {K}] [nm :: Name] [t :: K] [post :: {K}] [pre ~ post] [[nm] ~ pre ++ post] pf acc r =>
39 f [pre] [nm] [t] [post] ! ! pf r.nm (acc (r -- nm)))
40 (fn _ => i) fl r
41
42 fun foldR2 [K] [tr1 :: K -> Type] [tr2 :: K -> Type] [tf :: {K} -> Type] [r ::: {K}]
43 (f : pre :: {K} -> nm :: Name -> t :: K -> post :: {K} -> [pre ~ post] => [[nm] ~ pre ++ post] =>
44 eq r (pre ++ [nm = t] ++ post) -> tr1 t -> tr2 t -> tf post -> tf ([nm = t] ++ post))
45 (i : tf []) (fl : folder r) (r1 : $(map tr1 r)) (r2 : $(map tr2 r)) : tf r =
46 @@fold [fn r' => $(map tr1 r') -> $(map tr2 r') -> tf r'] [r]
47 (fn [pre :: {K}] [nm :: Name] [t :: K] [post :: {K}] [pre ~ post] [[nm] ~ pre ++ post] pf acc r1 r2 =>
48 f [pre] [nm] [t] [post] ! ! pf r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
49 (fn _ _ => i) fl r1 r2
50
51 fun foldR3 [K] [tr1 :: K -> Type] [tr2 :: K -> Type] [tr3 :: K -> Type] [tf :: {K} -> Type] [r ::: {K}]
52 (f : pre :: {K} -> nm :: Name -> t :: K -> post :: {K} -> [pre ~ post] => [[nm] ~ pre ++ post] =>
53 eq r (pre ++ [nm = t] ++ post) -> tr1 t -> tr2 t -> tr3 t -> tf post -> tf ([nm = t] ++ post))
54 (i : tf []) (fl : folder r) (r1 : $(map tr1 r)) (r2 : $(map tr2 r)) (r3 : $(map tr3 r)) : tf r =
55 @@fold [fn r' => $(map tr1 r') -> $(map tr2 r') -> $(map tr3 r') -> tf r'] [r]
56 (fn [pre :: {K}] [nm :: Name] [t :: K] [post :: {K}] [pre ~ post] [[nm] ~ pre ++ post] pf acc r1 r2 r3 =>
57 f [pre] [nm] [t] [post] ! ! pf r1.nm r2.nm r3.nm (acc (r1 -- nm) (r2 -- nm) (r3 -- nm)))
58 (fn _ _ _ => i) fl r1 r2 r3
59
60 fun foldR4 [K] [tr1 :: K -> Type] [tr2 :: K -> Type] [tr3 :: K -> Type] [tr4 :: K -> Type] [tf :: {K} -> Type] [r ::: {K}]
61 (f : pre :: {K} -> nm :: Name -> t :: K -> post :: {K} -> [pre ~ post] => [[nm] ~ pre ++ post] =>
62 eq r (pre ++ [nm = t] ++ post) -> tr1 t -> tr2 t -> tr3 t -> tr4 t -> tf post -> tf ([nm = t] ++ post))
63 (i : tf []) (fl : folder r) (r1 : $(map tr1 r)) (r2 : $(map tr2 r)) (r3 : $(map tr3 r)) (r4 : $(map tr4 r)) : tf r =
64 @@fold [fn r' => $(map tr1 r') -> $(map tr2 r') -> $(map tr3 r') -> $(map tr4 r') -> tf r'] [r]
65 (fn [pre :: {K}] [nm :: Name] [t :: K] [post :: {K}] [pre ~ post] [[nm] ~ pre ++ post] pf acc r1 r2 r3 r4 =>
66 f [pre] [nm] [t] [post] ! ! pf r1.nm r2.nm r3.nm r4.nm (acc (r1 -- nm) (r2 -- nm) (r3 -- nm) (r4 -- nm)))
67 (fn _ _ _ _ => i) fl r1 r2 r3 r4
68
69 fun mp [K] [tr :: K -> Type] [tf :: K -> Type] [r ::: {K}]
70 (f : nm :: Name -> t :: K -> rest :: {K} -> [[nm] ~ rest] =>
71 eq r ([nm = t] ++ rest) -> tr t -> tf t)
72 (fl : folder r) (r : $(map tr r)) : $(map tf r) =
73 @@foldR [tr] [fn r => $(map tf r)] [r]
74 (fn [pre :: {K}] [nm :: Name] [t :: K] [post :: {K}] [pre ~ post] [[nm] ~ pre ++ post] pf r acc =>
75 {nm = f [nm] [t] [pre ++ post] ! pf r} ++ acc)
76 {} fl r