comparison lib/top.ur @ 411:06fcddcd20d3

Sum demo, minus inference of {Unit}s
author Adam Chlipala <adamc@hcoop.net>
date Tue, 21 Oct 2008 19:24:39 -0400
parents 8084fa9216de
children df4cbd90a26e
comparison
equal deleted inserted replaced
410:c5a3d223f157 411:06fcddcd20d3
3 con fstTT (t :: (Type * Type)) = t.1 3 con fstTT (t :: (Type * Type)) = t.1
4 con sndTT (t :: (Type * Type)) = t.2 4 con sndTT (t :: (Type * Type)) = t.2
5 5
6 con mapTT (f :: Type -> Type) = fold (fn nm t acc [[nm] ~ acc] => 6 con mapTT (f :: Type -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
7 [nm = f t] ++ acc) [] 7 [nm = f t] ++ acc) []
8
9 con mapUT = fn f :: Type => fold (fn nm t acc [[nm] ~ acc] =>
10 [nm = f] ++ acc) []
8 11
9 con mapT2T (f :: (Type * Type) -> Type) = fold (fn nm t acc [[nm] ~ acc] => 12 con mapT2T (f :: (Type * Type) -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
10 [nm = f t] ++ acc) [] 13 [nm = f t] ++ acc) []
11 14
12 con ex = fn tf :: (Type -> Type) => 15 con ex = fn tf :: (Type -> Type) =>
19 fun compose (t1 ::: Type) (t2 ::: Type) (t3 ::: Type) 22 fun compose (t1 ::: Type) (t2 ::: Type) (t3 ::: Type)
20 (f1 : t2 -> t3) (f2 : t1 -> t2) (x : t1) = f1 (f2 x) 23 (f1 : t2 -> t3) (f2 : t1 -> t2) (x : t1) = f1 (f2 x)
21 24
22 fun txt (t ::: Type) (ctx ::: {Unit}) (use ::: {Type}) (sh : show t) (v : t) = 25 fun txt (t ::: Type) (ctx ::: {Unit}) (use ::: {Type}) (sh : show t) (v : t) =
23 cdata (@show sh v) 26 cdata (@show sh v)
27
28 fun foldUR (tf :: Type) (tr :: {Unit} -> Type)
29 (f : nm :: Name -> rest :: {Unit}
30 -> fn [[nm] ~ rest] =>
31 tf -> tr rest -> tr ([nm] ++ rest))
32 (i : tr []) =
33 fold [fn r :: {Unit} => $(mapUT tf r) -> tr r]
34 (fn (nm :: Name) (t :: Unit) (rest :: {Unit}) (acc : $(mapUT tf rest) -> tr rest)
35 [[nm] ~ rest] (r : $([nm = tf] ++ mapUT tf rest)) =>
36 f [nm] [rest] r.nm (acc (r -- nm)))
37 (fn _ => i)
24 38
25 fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type) 39 fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type)
26 (f : nm :: Name -> t :: Type -> rest :: {Type} 40 (f : nm :: Name -> t :: Type -> rest :: {Type}
27 -> fn [[nm] ~ rest] => 41 -> fn [[nm] ~ rest] =>
28 tf t -> tr rest -> tr ([nm = t] ++ rest)) 42 tf t -> tr rest -> tr ([nm = t] ++ rest))