From 20fe6fd5bb27486a7f3483ead05061e967c5a105 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 5 Dec 2009 14:01:34 -0500 Subject: Represent FFI function names as strings, to deal with cross-file recursion --- lib/js/urweb.js | 5 +++-- lib/ur/list.ur | 24 +++++++++++++----------- lib/ur/list.urs | 2 ++ lib/ur/string.ur | 11 +++++++++++ lib/ur/string.urs | 2 ++ 5 files changed, 31 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 98b615c0..863271d9 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -505,6 +505,7 @@ function eh(x) { function ts(x) { return x.toString() } function bs(b) { return (b ? "True" : "False") } +function id(x) { return x; } function sub(s, i) { return s.charAt(i); } function suf(s, i) { return s.substring(i); } function slen(s) { return s.length; } @@ -1049,10 +1050,10 @@ function exec1(env, stack, e) { break; case "f": if (e.a == null) - e = {c: "c", v: e.f()}; + e = {c: "c", v: (eval(e.f))()}; else { var args = []; - stack = cons({c: "f", f: e.f, args: args, pos: 0, a: e.a.next}, stack); + stack = cons({c: "f", f: eval(e.f), args: args, pos: 0, a: e.a.next}, stack); if (!e.a.data.c) alert("[2] fr.f = " + e.f + "; 0 = " + e.a.data); e = e.a.data; } diff --git a/lib/ur/list.ur b/lib/ur/list.ur index 58f9e23e..3abd8b97 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -21,7 +21,7 @@ val eq = fn [a] (_ : eq a) => mkEq eq' end -fun foldl [a] [b] f = +fun foldl [a] [b] (f : a -> b -> b) = let fun foldl' acc ls = case ls of @@ -31,6 +31,18 @@ fun foldl [a] [b] f = foldl' end +val rev = fn [a] => + let + fun rev' acc (ls : list a) = + case ls of + [] => acc + | x :: ls => rev' (x :: acc) ls + in + rev' [] + end + +fun foldr [a] [b] f (acc : b) (ls : list a) = foldl f acc (rev ls) + fun foldlAbort [a] [b] f = let fun foldlAbort' acc ls = @@ -54,16 +66,6 @@ val length = fn [a] => length' 0 end -val rev = fn [a] => - let - fun rev' acc (ls : list a) = - case ls of - [] => acc - | x :: ls => rev' (x :: acc) ls - in - rev' [] - end - fun foldlMapAbort [a] [b] [c] f = let fun foldlMapAbort' ls' acc ls = diff --git a/lib/ur/list.urs b/lib/ur/list.urs index df1c8a52..5f3fad9c 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -8,6 +8,8 @@ val foldlAbort : a ::: Type -> b ::: Type -> (a -> b -> option b) -> b -> t a -> val foldlMapAbort : a ::: Type -> b ::: Type -> c ::: Type -> (a -> b -> option (c * b)) -> b -> t a -> option (t c * b) +val foldr : a ::: Type -> b ::: Type -> (a -> b -> b) -> b -> t a -> b + val length : a ::: Type -> t a -> int val rev : a ::: Type -> t a -> t a diff --git a/lib/ur/string.ur b/lib/ur/string.ur index fb5a3f97..41ec666d 100644 --- a/lib/ur/string.ur +++ b/lib/ur/string.ur @@ -26,3 +26,14 @@ fun msplit {Haystack = s, Needle = chs} = | Some i => Some (substring s {Start = 0, Len = i}, sub s i, substring s {Start = i + 1, Len = length s - i - 1}) + +fun all f s = + let + val len = length s + + fun al i = + i >= len + || (f (sub s i) && al (i + 1)) + in + al 0 + end diff --git a/lib/ur/string.urs b/lib/ur/string.urs index 1b584c08..fda30ad9 100644 --- a/lib/ur/string.urs +++ b/lib/ur/string.urs @@ -18,3 +18,5 @@ val substring : t -> {Start : int, Len : int} -> string val split : t -> char -> option (string * string) val msplit : {Haystack : t, Needle : t} -> option (string * char * string) + +val all : (char -> bool) -> string -> bool -- cgit v1.2.3