[MLton-commit] r6584
Vesa Karvonen
vesak at mlton.org
Wed Apr 9 01:22:10 PDT 2008
Moved matches last to reduce repetition.
----------------------------------------------------------------------
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-08 22:52:09 UTC (rev 6583)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/example/iter/countdown.sml 2008-04-09 08:21:52 UTC (rev 6584)
@@ -32,22 +32,22 @@
datatype b = ADD | SUB | MUL | DIV
-fun valid ADD _ _ = true
- | valid SUB x y = x > y
- | valid MUL _ _ = true
- | valid DIV x y = x mod y = 0
+fun valid x y = fn ADD => true
+ | SUB => x > y
+ | MUL => true
+ | DIV => x mod y = 0
-fun apply ADD x y = x + y
- | apply SUB x y = x - y
- | apply MUL x y = x * y
- | apply DIV x y = x div y
+fun apply x y = fn ADD => x + y
+ | SUB => x - y
+ | MUL => x * y
+ | DIV => x div y
datatype x = VAL of int | APP of b * x * x
fun eval (VAL n) e = if n > 0 then e n else ()
- | eval (APP (b, l, r)) e = eval l (fn l =>
- eval r (fn r =>
- if valid b l r then e (apply b l r) else ()))
+ | eval (APP (b, l, r)) e = eval l (fn x =>
+ eval r (fn y =>
+ if valid x y b then e (apply x y b) else ()))
(*** Combinatorial functions ***)
@@ -86,7 +86,7 @@
(*** Combining generation and evaluation ***)
fun combine' (l, x) (r, y) e =
- bops (fn b => if valid b x y then e (APP (b, l, r), apply b x y) else ())
+ bops (fn b => if valid x y b then e (APP (b, l, r), apply x y b) else ())
fun results [] _ = ()
| results [n] e = if n > 0 then e (VAL n, n) else ()
@@ -100,13 +100,13 @@
(*** Exploiting numeric properties ***)
-fun valid' ADD x y = x <= y
- | valid' SUB x y = x > y
- | valid' MUL x y = x <= y andalso 1 < x
- | valid' DIV x y = y <> 1 andalso x mod y = 0
+fun valid' x y = fn ADD => x <= y
+ | SUB => x > y
+ | MUL => x <= y andalso 1 < x
+ | DIV => y <> 1 andalso x mod y = 0
fun combine'' (l, x) (r, y) e =
- bops (fn b => if valid' b x y then e (APP (b, l, r), apply b x y) else ())
+ bops (fn b => if valid' x y b then e (APP (b, l, r), apply x y b) else ())
fun results' [] _ = ()
| results' [n] e = if n > 0 then e (VAL n, n) else ()
More information about the MLton-commit
mailing list