[MLton-commit] r6585
Vesa Karvonen
vesak at mlton.org
Wed Apr 9 04:28:56 PDT 2008
A couple of clear simplifications using iterator combinators.
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/example/iter/countdown.sml
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/example/iter/countdown.sml
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/example/iter/countdown.sml 2008-04-09 08:21:52 UTC (rev 6584)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/example/iter/countdown.sml 2008-04-09 11:28:55 UTC (rev 6585)
@@ -28,6 +28,8 @@
* version.
*)
+open Iter.Monad Iter
+
(*** Expressions ***)
datatype b = ADD | SUB | MUL | DIV
@@ -58,10 +60,10 @@
| interleave x (y::ys) e =
(e (x::y::ys) ; interleave x ys (fn ys => e (y::ys)))
-fun perms [] e = e [] : unit
- | perms (x::xs) e = perms xs (fn p => interleave x p e)
+fun perms [] = return []
+ | perms (x::xs) = perms xs >>= interleave x
-fun choices xs e = subs xs (fn s => perms s e)
+fun choices xs = subs xs >>= perms
(*** Brute force solution ***)
@@ -71,7 +73,7 @@
fun bops e = (e ADD ; e SUB ; e MUL ; e DIV) : unit
-fun combine l r e = bops (fn b => e (APP (b, l, r)))
+fun combine l r = map (fn b => APP (b, l, r)) bops
fun exprs [] _ = ()
| exprs [n] e = e (VAL n)
More information about the MLton-commit
mailing list