[MLton-commit] r6521

Vesa Karvonen vesak at mlton.org
Mon Mar 31 11:01:16 PST 2008


Added Iter.intersperse.  Fixed module path OS -> BasisOS.

----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/extended-basis/unstable/detail/control/iter.sml
U   mltonlib/trunk/com/ssh/extended-basis/unstable/public/control/iter.sig

----------------------------------------------------------------------

Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/control/iter.sml
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/control/iter.sml	2008-03-30 22:07:41 UTC (rev 6520)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/control/iter.sml	2008-03-31 19:01:15 UTC (rev 6521)
@@ -19,6 +19,11 @@
                 fun a <|> b = b o obs a)
    open Monad
 
+   fun intersperse x aM e =
+       case ref true
+        of isFirst =>
+           aM (fn a => (if !isFirst then isFirst := false else e x ; e a))
+
    fun unfold g s f =
        case g s of NONE => () | SOME (x, s) => (f x : Unit.t ; unfold g s f)
 
@@ -99,7 +104,7 @@
    val inWord8Vector = flip Word8Vector.app
 
    fun inDir d e = let
-      open OS.FileSys
+      open BasisOS.FileSys
       val i = openDir d
       fun lp () =
           case readDir i

Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/control/iter.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/control/iter.sig	2008-03-30 22:07:41 UTC (rev 6520)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/control/iter.sig	2008-03-31 19:01:15 UTC (rev 6521)
@@ -74,7 +74,27 @@
 
    (** == Monad ==
     *
-    * Iterators essentially form a monad with plus.
+    * Iterators essentially form a monad with plus and satisfy the same
+    * laws, notably the left distribution law, as the (lazy) List monad.
+    *
+    * Monad {zero} is iterator for the empty sequence:
+    *
+    *> zero = [<>]
+    *
+    * Monad {<|>} (plus) is iterator concatenation:
+    *
+    *> [<a(0), a(1), ...>]       <|> [<b(0), b(1), ...>] = [<a(0), a(1), ...>]
+    *> [<a(0), a(1), ..., a(n)>] <|> [<b(0), b(1), ...>] =
+    *>    [<a(0), a(1), ..., a(n)>, b(0), b(1), ...]
+    *
+    * Monad {return} is an iterator for the singleton sequence:
+    *
+    *> return x = [<x>]
+    *
+    * Monad {>>=} (bind) is mapping and concatenation ({concatMap}) of
+    * iterators:
+    *
+    *> [<a(0), a(1), ...>] >>= a2bI = a2bI a(0) <|> a2bI a(1) <|> ...
     *)
 
    include MONADP_CORE where type 'a monad = 'a t
@@ -92,7 +112,11 @@
    val iterate : 'a UnOp.t -> 'a -> 'a t
    (** {iterate f x = [<x, f x, f (f x), ...>]} *)
 
-   (** == Combinators == *)
+   (** == Frequently used Monad Combinators ==
+    *
+    * These combinators are copied from the {Monad} substructure, because
+    * they are frequently useful.
+    *)
 
    val filter : 'a UnPr.t -> 'a t UnOp.t
    (**
@@ -114,6 +138,11 @@
     * This is the same as {Monad.><}.
     *)
 
+   (** == Misc Combinators == *)
+
+   val intersperse : 'a -> 'a t UnOp.t
+   (** {intersperse x [<a(0), a(1), ...>] = [<a(0), x, a(1), x, ...>]} *)
+
    (** == Repetition == *)
 
    val repeat : 'a -> 'a t




More information about the MLton-commit mailing list