annotate lib/top.ur @ 388:2e93d18daf44

Monoize eq_[bool|string]
author Adam Chlipala <adamc@hcoop.net>
date Tue, 21 Oct 2008 09:52:52 -0400
parents 28d3d7210687
children 8084fa9216de
rev   line source
adamc@356 1 con idT (t :: Type) = t
adamc@356 2 con record (t :: {Type}) = $t
adamc@356 3 con fstTT (t :: (Type * Type)) = t.1
adamc@356 4 con sndTT (t :: (Type * Type)) = t.2
adamc@329 5
adamc@356 6 con mapTT (f :: Type -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
adamc@356 7 [nm = f t] ++ acc) []
adamc@325 8
adamc@356 9 con mapT2T (f :: (Type * Type) -> Type) = fold (fn nm t acc [[nm] ~ acc] =>
adamc@356 10 [nm = f t] ++ acc) []
adamc@339 11
adamc@339 12 con ex = fn tf :: (Type -> Type) =>
adamc@356 13 res ::: Type -> (choice :: Type -> tf choice -> res) -> res
adamc@339 14
adamc@339 15 fun ex (tf :: (Type -> Type)) (choice :: Type) (body : tf choice) : ex tf =
adamc@356 16 fn (res ::: Type) (f : choice :: Type -> tf choice -> res) =>
adamc@356 17 f [choice] body
adamc@339 18
adamc@356 19 fun compose (t1 ::: Type) (t2 ::: Type) (t3 ::: Type)
adamc@356 20 (f1 : t2 -> t3) (f2 : t1 -> t2) (x : t1) = f1 (f2 x)
adamc@325 21
adamc@356 22 fun txt (t ::: Type) (ctx ::: {Unit}) (use ::: {Type}) (sh : show t) (v : t) =
adamc@356 23 cdata (show sh v)
adamc@328 24
adamc@336 25 fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type)
adamc@356 26 (f : nm :: Name -> t :: Type -> rest :: {Type}
adamc@356 27 -> fn [[nm] ~ rest] =>
adamc@356 28 tf t -> tr rest -> tr ([nm = t] ++ rest))
adamc@356 29 (i : tr []) =
adamc@356 30 fold [fn r :: {Type} => $(mapTT tf r) -> tr r]
adamc@356 31 (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> tr rest)
adamc@356 32 [[nm] ~ rest] r =>
adamc@356 33 f [nm] [t] [rest] r.nm (acc (r -- nm)))
adamc@356 34 (fn _ => i)
adamc@336 35
adamc@339 36 fun foldT2R (tf :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type)
adamc@367 37 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
adamc@367 38 -> fn [[nm] ~ rest] =>
adamc@367 39 tf t -> tr rest -> tr ([nm = t] ++ rest))
adamc@367 40 (i : tr []) =
adamc@356 41 fold [fn r :: {(Type * Type)} => $(mapT2T tf r) -> tr r]
adamc@356 42 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
adamc@356 43 (acc : _ -> tr rest) [[nm] ~ rest] r =>
adamc@356 44 f [nm] [t] [rest] r.nm (acc (r -- nm)))
adamc@356 45 (fn _ => i)
adamc@339 46
adamc@330 47 fun foldTR2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (tr :: {Type} -> Type)
adamc@367 48 (f : nm :: Name -> t :: Type -> rest :: {Type}
adamc@367 49 -> fn [[nm] ~ rest] =>
adamc@367 50 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
adamc@367 51 (i : tr []) =
adamc@356 52 fold [fn r :: {Type} => $(mapTT tf1 r) -> $(mapTT tf2 r) -> tr r]
adamc@356 53 (fn (nm :: Name) (t :: Type) (rest :: {Type})
adamc@356 54 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
adamc@356 55 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
adamc@356 56 (fn _ _ => i)
adamc@332 57
adamc@356 58 fun foldT2R2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type)
adamc@356 59 (tr :: {(Type * Type)} -> Type)
adamc@356 60 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
adamc@356 61 -> fn [[nm] ~ rest] =>
adamc@356 62 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
adamc@356 63 (i : tr []) =
adamc@356 64 fold [fn r :: {(Type * Type)} => $(mapT2T tf1 r) -> $(mapT2T tf2 r) -> tr r]
adamc@356 65 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
adamc@356 66 (acc : _ -> _ -> tr rest) [[nm] ~ rest] r1 r2 =>
adamc@356 67 f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
adamc@356 68 (fn _ _ => i)
adamc@339 69
adamc@336 70 fun foldTRX (tf :: Type -> Type) (ctx :: {Unit})
adamc@356 71 (f : nm :: Name -> t :: Type -> rest :: {Type}
adamc@356 72 -> fn [[nm] ~ rest] =>
adamc@356 73 tf t -> xml ctx [] []) =
adamc@356 74 foldTR [tf] [fn _ => xml ctx [] []]
adamc@356 75 (fn (nm :: Name) (t :: Type) (rest :: {Type}) [[nm] ~ rest] r acc =>
adamc@356 76 <xml>{f [nm] [t] [rest] r}{acc}</xml>)
adamc@360 77 <xml/>
adamc@336 78
adamc@339 79 fun foldT2RX (tf :: (Type * Type) -> Type) (ctx :: {Unit})
adamc@356 80 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
adamc@356 81 -> fn [[nm] ~ rest] =>
adamc@356 82 tf t -> xml ctx [] []) =
adamc@356 83 foldT2R [tf] [fn _ => xml ctx [] []]
adamc@356 84 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
adamc@356 85 [[nm] ~ rest] r acc =>
adamc@356 86 <xml>{f [nm] [t] [rest] r}{acc}</xml>)
adamc@360 87 <xml/>
adamc@339 88
adamc@332 89 fun foldTRX2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (ctx :: {Unit})
adamc@356 90 (f : nm :: Name -> t :: Type -> rest :: {Type}
adamc@356 91 -> fn [[nm] ~ rest] =>
adamc@356 92 tf1 t -> tf2 t -> xml ctx [] []) =
adamc@356 93 foldTR2 [tf1] [tf2] [fn _ => xml ctx [] []]
adamc@356 94 (fn (nm :: Name) (t :: Type) (rest :: {Type}) [[nm] ~ rest]
adamc@356 95 r1 r2 acc =>
adamc@356 96 <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
adamc@360 97 <xml/>
adamc@334 98
adamc@356 99 fun foldT2RX2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type)
adamc@356 100 (ctx :: {Unit})
adamc@356 101 (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)}
adamc@356 102 -> fn [[nm] ~ rest] =>
adamc@356 103 tf1 t -> tf2 t -> xml ctx [] []) =
adamc@356 104 foldT2R2 [tf1] [tf2] [fn _ => xml ctx [] []]
adamc@356 105 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
adamc@356 106 [[nm] ~ rest] r1 r2 acc =>
adamc@356 107 <xml>{f [nm] [t] [rest] r1 r2}{acc}</xml>)
adamc@360 108 <xml/>
adamc@339 109
adamc@356 110 fun queryX (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit})
adamc@356 111 (q : sql_query tables exps) [tables ~ exps]
adamc@356 112 (f : $(exps ++ fold (fn nm (fields :: {Type}) acc [[nm] ~ acc] =>
adamc@356 113 [nm = $fields] ++ acc) [] tables)
adamc@356 114 -> xml ctx [] []) =
adamc@356 115 query q
adamc@356 116 (fn fs acc => return <xml>{acc}{f fs}</xml>)
adamc@360 117 <xml/>
adamc@341 118
adamc@356 119 fun oneOrNoRows (tables ::: {{Type}}) (exps ::: {Type})
adamc@356 120 (q : sql_query tables exps) [tables ~ exps] =
adamc@356 121 query q
adamc@356 122 (fn fs _ => return (Some fs))
adamc@356 123 None