From c69e0c432107906261ab4c56cd88a8cfab3191fb Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 14 May 2009 13:18:31 -0400 Subject: Proper lifting of MonoEnv stored expressions; avoidance of onchange clobbering --- lib/js/urweb.js | 10 +++++++++- lib/ur/list.ur | 10 ++++++++++ lib/ur/list.urs | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 2943c897..d0322bff 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -301,11 +301,19 @@ function inp(t, s, content) { return x; } +function addOnChange(x, f) { + var old = x.onchange; + x.onchange = function() { old(); f (); }; +} + // Basic string operations function eh(x) { - return x.split("&").join("&").split("<").join("<").split(">").join(">"); + if (x == null) + return "NULL"; + else + return x.split("&").join("&").split("<").join("<").split(">").join(">"); } function ts(x) { return x.toString() } diff --git a/lib/ur/list.ur b/lib/ur/list.ur index ecec2bec..2ee60538 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -39,3 +39,13 @@ fun mapX (a ::: Type) (ctx ::: {Unit}) f = in mapX' end + +fun mapM (m ::: (Type -> Type)) (_ : monad m) (a ::: Type) (b ::: Type) f = + let + fun mapM' acc ls = + case ls of + [] => acc + | x :: ls => mapM' (x' <- f x; ls' <- acc; return (x' :: ls')) ls + in + mapM' (return []) + end diff --git a/lib/ur/list.urs b/lib/ur/list.urs index e9e097d4..d27ad997 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -7,3 +7,6 @@ val rev : a ::: Type -> t a -> t a val mp : a ::: Type -> b ::: Type -> (a -> b) -> t a -> t b val mapX : a ::: Type -> ctx ::: {Unit} -> (a -> xml ctx [] []) -> t a -> xml ctx [] [] + +val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type + -> (a -> m b) -> list a -> m (list b) -- cgit v1.2.3