[MLton-commit] r5329

Vesa Karvonen vesak at mlton.org
Sun Feb 25 23:43:48 PST 2007


Renamed Query (query.sml) to Maybe (maybe.sml).

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

U   mltonlib/trunk/com/ssh/misc-util/unstable/lib.mlb
A   mltonlib/trunk/com/ssh/misc-util/unstable/maybe.sml
D   mltonlib/trunk/com/ssh/misc-util/unstable/query.sml
U   mltonlib/trunk/com/ssh/misc-util/unstable/unit-test.sml

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

Modified: mltonlib/trunk/com/ssh/misc-util/unstable/lib.mlb
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/lib.mlb	2007-02-26 07:40:20 UTC (rev 5328)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/lib.mlb	2007-02-26 07:43:31 UTC (rev 5329)
@@ -23,7 +23,7 @@
    (* misc *)
    misc.sml
 
-   query.sml
+   maybe.sml
 
    bit-flags.sml
 

Copied: mltonlib/trunk/com/ssh/misc-util/unstable/maybe.sml (from rev 5328, mltonlib/trunk/com/ssh/misc-util/unstable/query.sml)
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/query.sml	2007-02-26 07:40:20 UTC (rev 5328)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/maybe.sml	2007-02-26 07:43:31 UTC (rev 5329)
@@ -0,0 +1,56 @@
+(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+(**
+ * A small combinator library for specifying queries.
+ *
+ * This is similar to the Maybe monad familiar from Haskell, but we can,
+ * of course, also perform effectful queries.  An example of an effectful
+ * query is {E} which queries the environment.
+ *)
+structure Maybe :> sig
+   type 'v t
+   include MONADP where type 'v monad = 'v t
+   val ` : 'a -> 'a t
+   val liftBinFn : ('a * 'b -> 'c) -> 'a t * 'b t -> 'c t (* XXX move to MONAD *)
+   val get : 'a t -> 'a Option.t
+   val mk : ('k -> 'v Option.t) -> 'k -> 'v t
+   val E : String.t -> String.t t
+   val ^` : String.t t BinOp.t
+   val @` : 'a t * ('a -> 'b Option.t) -> 'b t
+   val O : String.t -> Unit.t t
+   val L : String.t -> String.t t
+   val S : String.t -> String.t t
+end = struct
+   type 'v t = 'v Option.t Thunk.t
+   fun ` x = const (SOME x)
+   structure MonadP =
+     MkMonadP
+       (type 'v monad = 'v t
+        val return = `
+        fun (aM >>= a2bM) () = case aM () of NONE => NONE | SOME a => a2bM a ()
+        fun zero () = NONE
+        fun plus (l, r) () = case l () of NONE => r () | r => r)
+   open MonadP
+   fun liftBinFn f (aM, bM) = map f (aM >>* bM)
+   fun get q = q ()
+   fun mk f k () = f k
+   val E = mk OS.Process.getEnv
+   val op ^` = liftBinFn op ^
+   local
+      fun is s x = s = x
+      fun isE s = String.isPrefix (s^"=")
+      fun two f s = fn a::x::_ => SOME (f (s, a, x)) | _ => NONE
+      fun one f s = fn [] => NONE | x::_ => SOME (f (s, x))
+      val drop = flip List.dropWhile (CommandLine.arguments ())
+      fun arg p r e = mk (fn s => r e s o drop |< not o p s)
+   in
+      val L = arg isE one (fn (s, a) => String.extract (a, 1+size s, NONE))
+      val S = arg is two #3
+      val O = arg is one (const ())
+   end
+   fun aM @` from = aM >>= const o from
+end

Deleted: mltonlib/trunk/com/ssh/misc-util/unstable/query.sml
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/query.sml	2007-02-26 07:40:20 UTC (rev 5328)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/query.sml	2007-02-26 07:43:31 UTC (rev 5329)
@@ -1,56 +0,0 @@
-(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
- *
- * This code is released under the MLton license, a BSD-style license.
- * See the LICENSE file or http://mlton.org/License for details.
- *)
-
-(**
- * A small combinator library for specifying queries.
- *
- * This is similar to the Maybe monad familiar from Haskell, but we can,
- * of course, also perform effectful queries.  An example of an effectful
- * query is {E} which queries the environment.
- *)
-structure Query :> sig
-   type 'v t
-   include MONADP where type 'v monad = 'v t
-   val ` : 'a -> 'a t
-   val liftBinFn : ('a * 'b -> 'c) -> 'a t * 'b t -> 'c t (* XXX move to MONAD *)
-   val get : 'a t -> 'a Option.t
-   val mk : ('k -> 'v Option.t) -> 'k -> 'v t
-   val E : String.t -> String.t t
-   val ^` : String.t t BinOp.t
-   val @` : 'a t * ('a -> 'b Option.t) -> 'b t
-   val O : String.t -> Unit.t t
-   val L : String.t -> String.t t
-   val S : String.t -> String.t t
-end = struct
-   type 'v t = 'v Option.t Thunk.t
-   fun ` x = const (SOME x)
-   structure MonadP =
-     MkMonadP
-       (type 'v monad = 'v t
-        val return = `
-        fun (aM >>= a2bM) () = case aM () of NONE => NONE | SOME a => a2bM a ()
-        fun zero () = NONE
-        fun plus (l, r) () = case l () of NONE => r () | r => r)
-   open MonadP
-   fun liftBinFn f (aM, bM) = map f (aM >>* bM)
-   fun get q = q ()
-   fun mk f k () = f k
-   val E = mk OS.Process.getEnv
-   val op ^` = liftBinFn op ^
-   local
-      fun is s x = s = x
-      fun isE s = String.isPrefix (s^"=")
-      fun two f s = fn a::x::_ => SOME (f (s, a, x)) | _ => NONE
-      fun one f s = fn [] => NONE | x::_ => SOME (f (s, x))
-      val drop = flip List.dropWhile (CommandLine.arguments ())
-      fun arg p r e = mk (fn s => r e s o drop |< not o p s)
-   in
-      val L = arg isE one (fn (s, a) => String.extract (a, 1+size s, NONE))
-      val S = arg is two #3
-      val O = arg is one (const ())
-   end
-   fun aM @` from = aM >>= const o from
-end

Modified: mltonlib/trunk/com/ssh/misc-util/unstable/unit-test.sml
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/unit-test.sml	2007-02-26 07:40:20 UTC (rev 5328)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/unit-test.sml	2007-02-26 07:43:31 UTC (rev 5329)
@@ -192,7 +192,7 @@
       val pretty = pretty
 
       local
-         open Query
+         open Maybe
          val I = I.fromString
          val cols = sum [S"-w"@`I, L"--width"@`I, E"COLUMNS"@`I, `70]
       in




More information about the MLton-commit mailing list