[MLton-user] Extended Basis Library: Proposal for "swapped" bind
Geoffrey Alan Washburn
geoffw at cis.upenn.edu
Wed Apr 4 13:37:31 PDT 2007
This just introduces a new binary operation =<< which is the same as >>=
but takes the arguments in the reverse order. It might make sense to
also update fixity definitions in public/export/infixes.sml to include
this operator.
Index: ext-basis/detail/concept/mk-monad.fun
===================================================================
--- ext-basis/detail/concept/mk-monad.fun (revision 5492)
+++ ext-basis/detail/concept/mk-monad.fun (working copy)
@@ -12,6 +12,9 @@
fun map f aM = aM >>= pure f
fun thunk th = map th (return ())
type 'a monad_ex = 'a monad
+
+ fun op =<< x = ((op >>=) o Pair.swap) x
+
local
fun mk f (aM, bM) = aM >>= (fn a => bM >>= (fn b => return (f
(a, b))))
in
Index: ext-basis/public/concept/monad.sig
===================================================================
--- ext-basis/public/concept/monad.sig (revision 5492)
+++ ext-basis/public/concept/monad.sig (working copy)
@@ -34,6 +34,7 @@
signature MONAD_EX = sig
type 'a monad_ex
include FUNC where type 'a func = 'a monad_ex
+ val =<< : ('a -> 'b monad_ex) * 'a monad_ex -> 'b monad_ex
val >> : 'a monad_ex * 'b monad_ex -> 'b monad_ex
val >>& : 'a monad_ex * 'b monad_ex -> ('a, 'b) Product.t monad_ex
val >>* : 'a monad_ex * 'b monad_ex -> ('a * 'b) monad_
More information about the MLton-user
mailing list