[MLton-commit] r6514
Vesa Karvonen
vesak at mlton.org
Sat Mar 29 04:06:04 PST 2008
Added filter to monad with plus, which makes sense if the monad with plus
satisfies the "left distribution" law. In fact, it might make sense to
introduce a separate signature for monad with or (as opposed to monad with
plus) that satisfies the "left catch" law, but not the "left distribution"
law.
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-monad.fun
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-monad.fun
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-monad.fun 2008-03-29 11:58:47 UTC (rev 6513)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-monad.fun 2008-03-29 12:06:04 UTC (rev 6514)
@@ -1,4 +1,4 @@
-(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+(* Copyright (C) 2007-2008 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.
@@ -74,13 +74,15 @@
end
functor MkMonadP (Core : MONADP_CORE) : MONADP = struct
- infix <|>
+ infix <|> >>=
structure Monad = MkMonad (Core)
open Monad Core
type 'a monadp_ex = 'a monad
fun guard b = if b then return () else zero
+ fun filter p m = m >>= (fn x => if p x then return x else zero)
+
fun sumWith x2yM =
fn [] => zero
| [x] => x2yM x
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig 2008-03-29 11:58:47 UTC (rev 6513)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig 2008-03-29 12:06:04 UTC (rev 6514)
@@ -1,4 +1,4 @@
-(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+(* Copyright (C) 2007-2008 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.
@@ -107,6 +107,7 @@
signature MONADP_EX = sig
type 'a monadp_ex
val guard : Bool.t -> Unit.t monadp_ex
+ val filter : 'a UnPr.t -> 'a monadp_ex UnOp.t
val sum : 'a monadp_ex List.t -> 'a monadp_ex
val sumWith : ('a -> 'b monadp_ex) -> 'a List.t -> 'b monadp_ex
end
More information about the MLton-commit
mailing list