summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ur/basis.urs20
-rw-r--r--src/monoize.sml50
2 files changed, 40 insertions, 30 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index 8c28dacb..d3d4fe22 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -189,17 +189,17 @@ val sql_exp : tabs ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> rest ::: {T
-> nm :: Name
-> sql_exp tabs agg ([nm = t] ++ rest) t
+class sql_injectable_prim
+val sql_bool : sql_injectable_prim bool
+val sql_int : sql_injectable_prim int
+val sql_float : sql_injectable_prim float
+val sql_string : sql_injectable_prim string
+val sql_time : sql_injectable_prim time
+
class sql_injectable
-val sql_bool : sql_injectable bool
-val sql_int : sql_injectable int
-val sql_float : sql_injectable float
-val sql_string : sql_injectable string
-val sql_time : sql_injectable time
-val sql_option_bool : sql_injectable (option bool)
-val sql_option_int : sql_injectable (option int)
-val sql_option_float : sql_injectable (option float)
-val sql_option_string : sql_injectable (option string)
-val sql_option_time : sql_injectable (option time)
+val sql_prim : t ::: Type -> sql_injectable_prim t -> sql_injectable t
+val sql_option_prim : t ::: Type -> sql_injectable_prim t -> sql_injectable (option t)
+
val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
-> t ::: Type
-> sql_injectable t -> t -> sql_exp tables agg exps t
diff --git a/src/monoize.sml b/src/monoize.sml
index 87530070..1860fd19 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -163,6 +163,8 @@ fun monoType env =
| L.CFfi ("Basis", "sql_offset") =>
(L'.TFfi ("Basis", "string"), loc)
+ | L.CApp ((L.CFfi ("Basis", "sql_injectable_prim"), _), t) =>
+ (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
| L.CApp ((L.CFfi ("Basis", "sql_injectable"), _), t) =>
(L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
| L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_unary"), _), _), _), _) =>
@@ -1423,26 +1425,34 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "string"), loc),
(L'.EFfiApp ("Basis", "sqlifyTime", [(L'.ERel 0, loc)]), loc)), loc),
fm)
- | L.EFfi ("Basis", "sql_option_int") =>
- ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "int"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
- (L'.EFfiApp ("Basis", "sqlifyIntN", [(L'.ERel 0, loc)]), loc)), loc),
- fm)
- | L.EFfi ("Basis", "sql_option_float") =>
- ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "float"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
- (L'.EFfiApp ("Basis", "sqlifyFloatN", [(L'.ERel 0, loc)]), loc)), loc),
- fm)
- | L.EFfi ("Basis", "sql_option_bool") =>
- ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "bool"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
- (L'.EFfiApp ("Basis", "sqlifyBoolN", [(L'.ERel 0, loc)]), loc)), loc),
- fm)
- | L.EFfi ("Basis", "sql_option_string") =>
- ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "string"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
- (L'.EFfiApp ("Basis", "sqlifyStringN", [(L'.ERel 0, loc)]), loc)), loc),
- fm)
- | L.EFfi ("Basis", "sql_option_time") =>
- ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "time"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
- (L'.EFfiApp ("Basis", "sqlifyTimeN", [(L'.ERel 0, loc)]), loc)), loc),
- fm)
+ | L.ECApp ((L.EFfi ("Basis", "sql_prim"), _), t) =>
+ let
+ val t = monoType env t
+ val tf = (L'.TFun (t, (L'.TFfi ("Basis", "string"), loc)), loc)
+ in
+ ((L'.EAbs ("f", tf, tf, (L'.ERel 0, loc)), loc),
+ fm)
+ end
+ | L.ECApp ((L.EFfi ("Basis", "sql_option_prim"), _), t) =>
+ let
+ val t = monoType env t
+ val s = (L'.TFfi ("Basis", "string"), loc)
+ in
+ ((L'.EAbs ("f",
+ (L'.TFun (t, s), loc),
+ (L'.TFun ((L'.TOption t, loc), s), loc),
+ (L'.EAbs ("x",
+ (L'.TOption t, loc),
+ s,
+ (L'.ECase ((L'.ERel 0, loc),
+ [((L'.PNone t, loc),
+ (L'.EPrim (Prim.String "NULL"), loc)),
+ ((L'.PSome (t, (L'.PVar ("y", t), loc)), loc),
+ (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))],
+ {disc = (L'.TOption t, loc),
+ result = s}), loc)), loc)), loc),
+ fm)
+ end
| L.ECApp ((L.EFfi ("Basis", "sql_subset"), _), _) =>
((L'.ERecord [], loc), fm)