diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-08-21 13:41:57 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-08-21 13:41:57 -0400 |
commit | 9239ce8a90f9c983881216cfece4161a831216d4 (patch) | |
tree | 048f39efd512e604237cc836a8b2ee536ac75c57 | |
parent | 1e022eb78e7ca3fd15634e3845756b9c14209cf3 (diff) |
Fix another list unurlification segfault bug; List.foldlMi
-rw-r--r-- | lib/ur/list.ur | 12 | ||||
-rw-r--r-- | lib/ur/list.urs | 3 | ||||
-rw-r--r-- | src/cjr_print.sml | 2 | ||||
-rw-r--r-- | tests/rpcList2.ur | 10 |
4 files changed, 24 insertions, 3 deletions
diff --git a/lib/ur/list.ur b/lib/ur/list.ur index 35440de2..6a754287 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -255,6 +255,18 @@ fun foldlM [m] (_ : monad m) [a] [b] f = foldlM' end +fun foldlMi [m] (_ : monad m) [a] [b] f = + let + fun foldlMi' i acc ls = + case ls of + [] => return acc + | x :: ls => + acc <- f i x acc; + foldlMi' (i + 1) acc ls + in + foldlMi' 0 + end + fun all [m] f = let fun all' ls = diff --git a/lib/ur/list.urs b/lib/ur/list.urs index 851d74bc..2a28d148 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -43,6 +43,9 @@ val exists : a ::: Type -> (a -> bool) -> t a -> bool val foldlM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type -> (a -> b -> m b) -> b -> t a -> m b +val foldlMi : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type + -> (int -> a -> b -> m b) -> b -> t a -> m b + val foldlMap : a ::: Type -> b ::: Type -> c ::: Type -> (a -> b -> c * b) -> b -> t a -> t c * b diff --git a/src/cjr_print.sml b/src/cjr_print.sml index 0b900218..4e3e1570 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -861,7 +861,7 @@ fun unurlify fromClient env (t, loc) = space, string "+=", space, - string "3, ((*request)[0] == '/' ? ((*request)[0] = 0, (*request)++) : NULL)) : ((!strncmp(*request, \"Cons\", 4) && ((*request)[4] == 0 ", + string "3, ((*request)[0] == '/' ? ((*request)[0] = 0, ++*request) : NULL), NULL) : ((!strncmp(*request, \"Cons\", 4) && ((*request)[4] == 0 ", string "|| (*request)[4] == '/')) ? (*request", space, string "+=", diff --git a/tests/rpcList2.ur b/tests/rpcList2.ur index c0739b84..e3ebb456 100644 --- a/tests/rpcList2.ur +++ b/tests/rpcList2.ur @@ -1,7 +1,13 @@ -fun rpcFunc l : transaction {} = return () +fun showList l = case l of + [] => "[]" + | h :: t => strcat (strcat (show h) " :: ") (showList t) + +fun rpcFunc l : transaction string = + case l of h :: _ => return (showList h) | [] => return "[]" fun main () : transaction page = return <xml><body> <button onclick={ - rpc (rpcFunc (("" :: []) :: [])) + s <- rpc (rpcFunc (("foo" :: []) :: [])); + alert s }/> </body></xml> |