Mercurial > urweb
changeset 1547:553a5cc3a4b5
Fix another list unurlification segfault bug; List.foldlMi
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 21 Aug 2011 13:41:57 -0400 |
parents | 133c71008bef |
children | 76dab73304a5 |
files | lib/ur/list.ur lib/ur/list.urs src/cjr_print.sml tests/rpcList2.ur |
diffstat | 4 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/ur/list.ur Sun Aug 21 10:55:31 2011 -0400 +++ b/lib/ur/list.ur Sun Aug 21 13:41:57 2011 -0400 @@ -255,6 +255,18 @@ 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 =
--- a/lib/ur/list.urs Sun Aug 21 10:55:31 2011 -0400 +++ b/lib/ur/list.urs Sun Aug 21 13:41:57 2011 -0400 @@ -43,6 +43,9 @@ 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
--- a/src/cjr_print.sml Sun Aug 21 10:55:31 2011 -0400 +++ b/src/cjr_print.sml Sun Aug 21 13:41:57 2011 -0400 @@ -861,7 +861,7 @@ 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 "+=",
--- a/tests/rpcList2.ur Sun Aug 21 10:55:31 2011 -0400 +++ b/tests/rpcList2.ur Sun Aug 21 13:41:57 2011 -0400 @@ -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>