comparison lib/top.ur @ 339:075b36dbb1a4

Crud supports INSERT
author Adam Chlipala <adamc@hcoop.net>
date Sun, 14 Sep 2008 15:10:04 -0400
parents 34847732cefc
children 389399d65331
comparison
equal deleted inserted replaced
338:e976b187d73a 339:075b36dbb1a4
1 con idT = fn t :: Type => t 1 con idT = fn t :: Type => t
2 con record = fn t :: {Type} => $t 2 con record = fn t :: {Type} => $t
3 con fstTT = fn t :: (Type * Type) => t.1
4 con sndTT = fn t :: (Type * Type) => t.2
3 5
4 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 =>
5 [nm = f t] ++ acc) [] 7 [nm = f t] ++ acc) []
8
9 con mapT2T (f :: (Type * Type) -> Type) = fold (fn nm t acc => [nm] ~ acc =>
10 [nm = f t] ++ acc) []
11
12 con ex = fn tf :: (Type -> Type) =>
13 res ::: Type -> (choice :: Type -> tf choice -> res) -> res
14
15 fun ex (tf :: (Type -> Type)) (choice :: Type) (body : tf choice) : ex tf =
16 fn (res ::: Type) (f : choice :: Type -> tf choice -> res) =>
17 f [choice] body
6 18
7 fun compose (t1 ::: Type) (t2 ::: Type) (t3 ::: Type) (f1 : t2 -> t3) (f2 : t1 -> t2) (x : t1) = f1 (f2 x) 19 fun compose (t1 ::: Type) (t2 ::: Type) (t3 ::: Type) (f1 : t2 -> t3) (f2 : t1 -> t2) (x : t1) = f1 (f2 x)
8 20
9 fun txt (t ::: Type) (ctx ::: {Unit}) (use ::: {Type}) (sh : show t) (v : t) = cdata (show sh v) 21 fun txt (t ::: Type) (ctx ::: {Unit}) (use ::: {Type}) (sh : show t) (v : t) = cdata (show sh v)
10 22
16 (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> tr rest) => 28 (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> tr rest) =>
17 [[nm] ~ rest] => 29 [[nm] ~ rest] =>
18 fn r => f [nm] [t] [rest] r.nm (acc (r -- nm))) 30 fn r => f [nm] [t] [rest] r.nm (acc (r -- nm)))
19 (fn _ => i) 31 (fn _ => i)
20 32
33 fun foldT2R (tf :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type)
34 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
35 -> tf t -> tr rest -> tr ([nm = t] ++ rest))
36 (i : tr []) =
37 fold [fn r :: {(Type * Type)} => $(mapT2T tf r) -> tr r]
38 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) (acc : _ -> tr rest) =>
39 [[nm] ~ rest] =>
40 fn r => f [nm] [t] [rest] r.nm (acc (r -- nm)))
41 (fn _ => i)
42
21 fun foldTR2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (tr :: {Type} -> Type) 43 fun foldTR2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (tr :: {Type} -> Type)
22 (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest 44 (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest
23 -> tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest)) 45 -> tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
24 (i : tr []) = 46 (i : tr []) =
25 fold [fn r :: {Type} => $(mapTT tf1 r) -> $(mapTT tf2 r) -> tr r] 47 fold [fn r :: {Type} => $(mapTT tf1 r) -> $(mapTT tf2 r) -> tr r]
26 (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> _ -> tr rest) => 48 (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> _ -> tr rest) =>
49 [[nm] ~ rest] =>
50 fn r1 r2 => f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
51 (fn _ _ => i)
52
53 fun foldT2R2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type)
54 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
55 -> tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
56 (i : tr []) =
57 fold [fn r :: {(Type * Type)} => $(mapT2T tf1 r) -> $(mapT2T tf2 r) -> tr r]
58 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) (acc : _ -> _ -> tr rest) =>
27 [[nm] ~ rest] => 59 [[nm] ~ rest] =>
28 fn r1 r2 => f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm))) 60 fn r1 r2 => f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
29 (fn _ _ => i) 61 (fn _ _ => i)
30 62
31 fun foldTRX (tf :: Type -> Type) (ctx :: {Unit}) 63 fun foldTRX (tf :: Type -> Type) (ctx :: {Unit})
35 (fn (nm :: Name) (t :: Type) (rest :: {Type}) => 67 (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
36 [[nm] ~ rest] => 68 [[nm] ~ rest] =>
37 fn r acc => <xml>{f [nm] [t] [rest] r}{acc}</xml>) 69 fn r acc => <xml>{f [nm] [t] [rest] r}{acc}</xml>)
38 <xml></xml> 70 <xml></xml>
39 71
72 fun foldT2RX (tf :: (Type * Type) -> Type) (ctx :: {Unit})
73 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
74 -> tf t -> xml ctx [] []) =
75 foldT2R [tf] [fn _ => xml ctx [] []]
76 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
77 [[nm] ~ rest] =>
78 fn r acc => <xml>{f [nm] [t] [rest] r}{acc}</xml>)
79 <xml></xml>
80
40 fun foldTRX2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (ctx :: {Unit}) 81 fun foldTRX2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (ctx :: {Unit})
41 (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest 82 (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest
42 -> tf1 t -> tf2 t -> xml ctx [] []) = 83 -> tf1 t -> tf2 t -> xml ctx [] []) =
43 foldTR2 [tf1] [tf2] [fn _ => xml ctx [] []] 84 foldTR2 [tf1] [tf2] [fn _ => xml ctx [] []]
44 (fn (nm :: Name) (t :: Type) (rest :: {Type}) => 85 (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
86 [[nm] ~ rest] =>
87 fn r1 r2 acc => <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
88 <xml></xml>
89
90 fun foldT2RX2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type) (ctx :: {Unit})
91 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
92 -> tf1 t -> tf2 t -> xml ctx [] []) =
93 foldT2R2 [tf1] [tf2] [fn _ => xml ctx [] []]
94 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
45 [[nm] ~ rest] => 95 [[nm] ~ rest] =>
46 fn r1 r2 acc => <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>) 96 fn r1 r2 acc => <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
47 <xml></xml> 97 <xml></xml>
48 98
49 fun queryX (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit}) (q : sql_query tables exps) = 99 fun queryX (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit}) (q : sql_query tables exps) =