adamc@329: con idT = fn t :: Type => t
adamc@329: con record = fn t :: {Type} => $t
adamc@339: con fstTT = fn t :: (Type * Type) => t.1
adamc@339: con sndTT = fn t :: (Type * Type) => t.2
adamc@329:
adamc@325: con mapTT (f :: Type -> Type) = fold (fn nm t acc => [nm] ~ acc =>
adamc@325: [nm = f t] ++ acc) []
adamc@325:
adamc@339: con mapT2T (f :: (Type * Type) -> Type) = fold (fn nm t acc => [nm] ~ acc =>
adamc@339: [nm = f t] ++ acc) []
adamc@339:
adamc@339: con ex = fn tf :: (Type -> Type) =>
adamc@339: res ::: Type -> (choice :: Type -> tf choice -> res) -> res
adamc@339:
adamc@339: fun ex (tf :: (Type -> Type)) (choice :: Type) (body : tf choice) : ex tf =
adamc@339: fn (res ::: Type) (f : choice :: Type -> tf choice -> res) =>
adamc@339: f [choice] body
adamc@339:
adamc@325: fun compose (t1 ::: Type) (t2 ::: Type) (t3 ::: Type) (f1 : t2 -> t3) (f2 : t1 -> t2) (x : t1) = f1 (f2 x)
adamc@325:
adamc@325: fun txt (t ::: Type) (ctx ::: {Unit}) (use ::: {Type}) (sh : show t) (v : t) = cdata (show sh v)
adamc@328:
adamc@336: fun foldTR (tf :: Type -> Type) (tr :: {Type} -> Type)
adamc@336: (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest
adamc@345: => tf t -> tr rest -> tr ([nm = t] ++ rest))
adamc@336: (i : tr []) =
adamc@336: fold [fn r :: {Type} => $(mapTT tf r) -> tr r]
adamc@336: (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> tr rest) =>
adamc@336: [[nm] ~ rest] =>
adamc@336: fn r => f [nm] [t] [rest] r.nm (acc (r -- nm)))
adamc@336: (fn _ => i)
adamc@336:
adamc@339: fun foldT2R (tf :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type)
adamc@339: (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
adamc@345: => tf t -> tr rest -> tr ([nm = t] ++ rest))
adamc@339: (i : tr []) =
adamc@339: fold [fn r :: {(Type * Type)} => $(mapT2T tf r) -> tr r]
adamc@339: (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) (acc : _ -> tr rest) =>
adamc@339: [[nm] ~ rest] =>
adamc@339: fn r => f [nm] [t] [rest] r.nm (acc (r -- nm)))
adamc@339: (fn _ => i)
adamc@339:
adamc@330: fun foldTR2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (tr :: {Type} -> Type)
adamc@328: (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest
adamc@345: => tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
adamc@328: (i : tr []) =
adamc@328: fold [fn r :: {Type} => $(mapTT tf1 r) -> $(mapTT tf2 r) -> tr r]
adamc@328: (fn (nm :: Name) (t :: Type) (rest :: {Type}) (acc : _ -> _ -> tr rest) =>
adamc@328: [[nm] ~ rest] =>
adamc@328: fn r1 r2 => f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
adamc@328: (fn _ _ => i)
adamc@332:
adamc@339: fun foldT2R2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type) (tr :: {(Type * Type)} -> Type)
adamc@339: (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
adamc@345: => tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
adamc@339: (i : tr []) =
adamc@339: fold [fn r :: {(Type * Type)} => $(mapT2T tf1 r) -> $(mapT2T tf2 r) -> tr r]
adamc@339: (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) (acc : _ -> _ -> tr rest) =>
adamc@339: [[nm] ~ rest] =>
adamc@339: fn r1 r2 => f [nm] [t] [rest] r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
adamc@339: (fn _ _ => i)
adamc@339:
adamc@336: fun foldTRX (tf :: Type -> Type) (ctx :: {Unit})
adamc@336: (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest
adamc@345: => tf t -> xml ctx [] []) =
adamc@336: foldTR [tf] [fn _ => xml ctx [] []]
adamc@336: (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
adamc@336: [[nm] ~ rest] =>
adamc@336: fn r acc => {f [nm] [t] [rest] r}{acc})
adamc@336:
adamc@336:
adamc@339: fun foldT2RX (tf :: (Type * Type) -> Type) (ctx :: {Unit})
adamc@339: (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
adamc@345: => tf t -> xml ctx [] []) =
adamc@339: foldT2R [tf] [fn _ => xml ctx [] []]
adamc@339: (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
adamc@339: [[nm] ~ rest] =>
adamc@339: fn r acc => {f [nm] [t] [rest] r}{acc})
adamc@339:
adamc@339:
adamc@332: fun foldTRX2 (tf1 :: Type -> Type) (tf2 :: Type -> Type) (ctx :: {Unit})
adamc@332: (f : nm :: Name -> t :: Type -> rest :: {Type} -> [nm] ~ rest
adamc@345: => tf1 t -> tf2 t -> xml ctx [] []) =
adamc@332: foldTR2 [tf1] [tf2] [fn _ => xml ctx [] []]
adamc@332: (fn (nm :: Name) (t :: Type) (rest :: {Type}) =>
adamc@332: [[nm] ~ rest] =>
adamc@332: fn r1 r2 acc => {f [nm] [t] [rest] r1 r2}{acc})
adamc@332:
adamc@334:
adamc@339: fun foldT2RX2 (tf1 :: (Type * Type) -> Type) (tf2 :: (Type * Type) -> Type) (ctx :: {Unit})
adamc@339: (f : nm :: Name -> t :: (Type * Type) -> rest :: {(Type * Type)} -> [nm] ~ rest
adamc@345: => tf1 t -> tf2 t -> xml ctx [] []) =
adamc@339: foldT2R2 [tf1] [tf2] [fn _ => xml ctx [] []]
adamc@339: (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
adamc@339: [[nm] ~ rest] =>
adamc@339: fn r1 r2 acc => {f [nm] [t] [rest] r1 r2}{acc})
adamc@339:
adamc@339:
adamc@334: fun queryX (tables ::: {{Type}}) (exps ::: {Type}) (ctx ::: {Unit}) (q : sql_query tables exps) =
adamc@334: [tables ~ exps] =>
adamc@334: fn (f : $(exps ++ fold (fn nm (fields :: {Type}) acc => [nm] ~ acc => [nm = $fields] ++ acc) [] tables)
adamc@334: -> xml ctx [] []) =>
adamc@334: query q
adamc@334: (fn fs acc => return {acc}{f fs})
adamc@334:
adamc@341:
adamc@341: fun oneOrNoRows (tables ::: {{Type}}) (exps ::: {Type}) (q : sql_query tables exps) =
adamc@341: [tables ~ exps] =>
adamc@341: query q
adamc@341: (fn fs _ => return (Some fs))
adamc@341: None