diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-06-07 16:45:00 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-06-07 16:45:00 -0400 |
commit | 005fbe2dd67c6ec77282179032f94ffa6cb7788c (patch) | |
tree | 30300e247037398cd77a827ae1c38b96d19baec7 | |
parent | 07249bc2c07b2af3b9decb84ce968e3005a19c0f (diff) |
Fix datatype import bug in Elaborate; fix server-side source setting; more standard library stuff
-rw-r--r-- | lib/ur/basis.urs | 1 | ||||
-rw-r--r-- | lib/ur/list.ur | 12 | ||||
-rw-r--r-- | lib/ur/list.urs | 3 | ||||
-rw-r--r-- | lib/ur/listPair.ur | 11 | ||||
-rw-r--r-- | lib/ur/listPair.urs | 2 | ||||
-rw-r--r-- | lib/ur/option.ur | 5 | ||||
-rw-r--r-- | lib/ur/option.urs | 2 | ||||
-rw-r--r-- | src/c/urweb.c | 6 | ||||
-rw-r--r-- | src/elaborate.sml | 4 | ||||
-rw-r--r-- | src/monoize.sml | 42 |
10 files changed, 85 insertions, 3 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index 50909804..c5c4f6f2 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -25,6 +25,7 @@ val eq_string : eq string val eq_char : eq char val eq_bool : eq bool val eq_time : eq time +val eq_option : t ::: Type -> eq t -> eq (option t) val mkEq : t ::: Type -> (t -> t -> bool) -> eq t class num diff --git a/lib/ur/list.ur b/lib/ur/list.ur index 771cddc3..60cd7316 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -171,3 +171,15 @@ fun all [m] f = in all' end + +fun app [m] (_ : monad m) [a] f = + let + fun app' ls = + case ls of + [] => return () + | x :: ls => + f x; + app' ls + in + app' + end diff --git a/lib/ur/list.urs b/lib/ur/list.urs index 6a653ba9..7906970a 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -35,3 +35,6 @@ val assoc : a ::: Type -> b ::: Type -> eq a -> a -> t (a * b) -> option b val search : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> option b val all : a ::: Type -> (a -> bool) -> t a -> bool + +val app : m ::: (Type -> Type) -> monad m -> a ::: Type + -> (a -> m unit) -> t a -> m unit diff --git a/lib/ur/listPair.ur b/lib/ur/listPair.ur index a46cf187..8d1c873e 100644 --- a/lib/ur/listPair.ur +++ b/lib/ur/listPair.ur @@ -8,3 +8,14 @@ fun mapX [a] [b] [ctx ::: {Unit}] f = in mapX' end + +fun all [a] [b] f = + let + fun all' ls1 ls2 = + case (ls1, ls2) of + ([], []) => True + | (x1 :: ls1, x2 :: ls2) => f x1 x2 && all' ls1 ls2 + | _ => False + in + all' + end diff --git a/lib/ur/listPair.urs b/lib/ur/listPair.urs index 55a34b3a..0c5e5443 100644 --- a/lib/ur/listPair.urs +++ b/lib/ur/listPair.urs @@ -1,2 +1,4 @@ val mapX : a ::: Type -> b ::: Type -> ctx ::: {Unit} -> (a -> b -> xml ctx [] []) -> list a -> list b -> xml ctx [] [] + +val all : a ::: Type -> b ::: Type -> (a -> b -> bool) -> list a -> list b -> bool diff --git a/lib/ur/option.ur b/lib/ur/option.ur index cb2a6b57..5ec093c0 100644 --- a/lib/ur/option.ur +++ b/lib/ur/option.ur @@ -4,3 +4,8 @@ fun isSome [a] x = case x of None => False | Some _ => True + +fun mp [a] [b] f x = + case x of + None => None + | Some y => Some (f y) diff --git a/lib/ur/option.urs b/lib/ur/option.urs index 97e52fda..ced6156e 100644 --- a/lib/ur/option.urs +++ b/lib/ur/option.urs @@ -1,3 +1,5 @@ datatype t = datatype Basis.option val isSome : a ::: Type -> t a -> bool + +val mp : a ::: Type -> b ::: Type -> (a -> b) -> t a -> t b diff --git a/src/c/urweb.c b/src/c/urweb.c index 0c6eefd5..864a5daa 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1278,12 +1278,12 @@ uw_unit uw_Basis_set_client_source(uw_context ctx, uw_Basis_int n, uw_Basis_stri size_t s_len = strlen(s); uw_check_script(ctx, 6 + INTS_MAX + s_len); - sprintf(ctx->script.front, "s%d.v=%n", (int)n, &len); + sprintf(ctx->script.front, "sv(s%d,%n", (int)n, &len); ctx->script.front += len; strcpy(ctx->script.front, s); ctx->script.front += s_len; - strcpy(ctx->script.front, ";"); - ctx->script.front++; + strcpy(ctx->script.front, ");"); + ctx->script.front += 2; return uw_unit_v; } diff --git a/src/elaborate.sml b/src/elaborate.sml index 92792cd5..3b147e00 100644 --- a/src/elaborate.sml +++ b/src/elaborate.sml @@ -3271,6 +3271,10 @@ and elabDecl (dAll as (d, loc), (env, denv, gs)) = val env = E.pushDatatype env n' xs xncs val t = (L'.CNamed n', loc) + val nxs = length xs + val t = ListUtil.foldli (fn (i, _, t) => + (L'.CApp (t, (L'.CRel (nxs - 1 - i), loc)), loc)) + t xs val env = foldl (fn ((x, n, to), env) => let val t = case to of diff --git a/src/monoize.sml b/src/monoize.sml index bdc8ef82..e0795b84 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -778,6 +778,48 @@ fun monoExp (env, st, fm) (all as (e, loc)) = (L'.TFfi ("Basis", "bool"), loc), (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc), fm) + | L.ECApp ((L.EFfi ("Basis", "eq_option"), _), t) => + let + val t = monoType env t + val t' = (L'.TOption t, loc) + val bool = (L'.TFfi ("Basis", "bool"), loc) + in + ((L'.EAbs ("f", (L'.TFun (t, (L'.TFun (t, bool), loc)), loc), + (L'.TFun (t', (L'.TFun (t', bool), loc)), loc), + (L'.EAbs ("x", t', (L'.TFun (t', bool), loc), + (L'.EAbs ("y", t', bool, + (L'.ECase ((L'.ERecord [("1", (L'.ERel 1, loc), t'), + ("2", (L'.ERel 0, loc), t')], loc), + [((L'.PRecord [("1", (L'.PNone t, loc), t'), + ("2", (L'.PNone t, loc), t')], loc), + (L'.ECon (L'.Enum, L'.PConFfi {mod = "Basis", + datatyp = "bool", + con = "True", + arg = NONE}, + NONE), loc)), + ((L'.PRecord [("1", (L'.PSome (t, + (L'.PVar ("x1", + t), loc)), + loc), t'), + ("2", (L'.PSome (t, + (L'.PVar ("x2", + t), loc)), + loc), t')], loc), + (L'.EApp ((L'.EApp ((L'.ERel 4, loc), + (L'.ERel 1, loc)), loc), + (L'.ERel 0, loc)), loc)), + ((L'.PWild, loc), + (L'.ECon (L'.Enum, L'.PConFfi {mod = "Basis", + datatyp = "bool", + con = "False", + arg = NONE}, + NONE), loc))], + {disc = (L'.TRecord [("1", t'), ("2", t')], loc), + result = (L'.TFfi ("Basis", "bool"), loc)}), + loc)), loc)), loc)), loc), + fm) + end + | L.ECApp ((L.EFfi ("Basis", "mkEq"), _), t) => let val t = monoType env t |