diff src/list_util.sml @ 34:44b5405e74c7

Elaborating module projection
author Adam Chlipala <adamc@hcoop.net>
date Tue, 17 Jun 2008 16:38:54 -0400
parents 1c91c5e6840f
children 02f42e9a1825
line wrap: on
line diff
--- a/src/list_util.sml	Thu Jun 12 17:41:32 2008 -0400
+++ b/src/list_util.sml	Tue Jun 17 16:38:54 2008 -0400
@@ -45,6 +45,26 @@
         mf
     end
 
+fun mapfoldB f =
+    let
+        fun mf ctx ls s =
+            case ls of
+                nil => S.Continue (nil, s)
+              | h :: t =>
+                let
+                    val (ctx, r) = f (ctx, h)
+                in
+                    case r s of
+                        S.Return x => S.Return x
+                      | S.Continue (h', s) =>
+                        case mf ctx t s of
+                            S.Return x => S.Return x
+                          | S.Continue (t', s) => S.Continue (h' :: t', s)
+                end
+    in
+        mf
+    end
+
 fun foldlMap f s =
     let
         fun fm (ls', s) ls =