[MLton-commit] r5478

Vesa Karvonen vesak at mlton.org
Thu Mar 29 05:30:30 PST 2007


Optimization and simplification.  With monads one probably should minimize
binds (>>=) as it is a user defined operation (and might be costly).

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

U   mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-monad.fun

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

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	2007-03-29 13:23:30 UTC (rev 5477)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-monad.fun	2007-03-29 13:30:29 UTC (rev 5478)
@@ -12,10 +12,14 @@
    fun map f aM = aM >>= pure f
    fun thunk th = map th (return ())
    type 'a monad_ex = 'a monad
-   fun aM >>* bM = aM >>= (fn a => bM >>= Fn.<\ (a, return))
-   fun fM >>@ aM = map Fn.\> (fM >>* aM)
-   fun aM >>& bM = map Product.& (aM >>* bM)
-   fun aM >> bM = map #2 (aM >>* bM)
+   local
+      fun mk f (aM, bM) = aM >>= (fn a => bM >>= (fn b => return (f (a, b))))
+   in
+      fun op >>  ? = mk #2 ?
+      fun op >>& ? = mk Product.& ?
+      fun op >>* ? = mk Fn.id ?
+      fun op >>@ ? = mk Fn.\> ?
+   end
 
    fun ignore m = map Effect.ignore m
    fun (y2zM oo x2yM) x = x2yM x >>= y2zM




More information about the MLton-commit mailing list