[svn] r6300: nemerle/trunk/lib/rlist.n
d
svnadmin at nemerle.org
Tue May 16 22:28:34 CEST 2006
Log:
Make use of the new, shorter lambda expr syntax.
Author: d
Date: Tue May 16 22:28:34 2006
New Revision: 6300
Modified:
nemerle/trunk/lib/rlist.n
Modified: nemerle/trunk/lib/rlist.n
==============================================================================
--- nemerle/trunk/lib/rlist.n (original)
+++ nemerle/trunk/lib/rlist.n Tue May 16 22:28:34 2006
@@ -370,7 +370,7 @@
*/
static _Update (f : 'a -> 'a, i : int, xs : RList ['a]) : RList ['a] {
match (xs) {
- | Zero (ps) => def f' (p) { match (p) { | Pair where (fst = x, snd = y) => if (i % 2 == 0) Pair (f (x), y) else Pair (x, f (y)) } }
+ | Zero (ps) => def f' (p) { if (i % 2 == 0) Pair (f (p.fst), p.snd) else Pair (p.fst, f (p.snd)) }
Zero (RList [Pair ['a]]._Update (f', i / 2, ps))
| One (x, ps) => if (i == 0) One (f (x), ps) else Cons (x, _Update (f, i - 1, Zero (ps)))
| Nil => throw Exception ("Subscript")
@@ -392,7 +392,7 @@
</returns>
*/
public static Update (i : int, y : 'a, xs : RList ['a]) : RList ['a] {
- _Update (fun (_) { y }, i, xs)
+ _Update (_ => y, i, xs)
}
/** Returns a new RList composed by substituting the [i]-th element
@@ -430,10 +430,8 @@
*/
public static FoldLeft ['b] (xs : RList ['a], acc : 'b, f : 'a * 'b -> 'b) : 'b {
match (xs) {
- | Zero (ps) => def f' (a, b) { f (a.snd, f (a.fst, b)) }
- RList [Pair ['a]].FoldLeft (ps, acc, f')
- | One (x, ps) => def f' (a, b) { f (a.snd, f (a.fst, b)) }
- RList [Pair ['a]].FoldLeft (ps, f (x, acc), f')
+ | Zero (ps) => RList [Pair ['a]].FoldLeft (ps, acc, (a, b) => f (a.snd, f (a.fst, b)))
+ | One (x, ps) => RList [Pair ['a]].FoldLeft (ps, f (x, acc), (a, b) => f (a.snd, f (a.fst, b)))
| Nil => acc
}
}
@@ -476,10 +474,8 @@
*/
public static FoldRight ['b] (xs : RList ['a], acc : 'b, f : 'a * 'b -> 'b) : 'b {
match (xs) {
- | Zero (ps) => def f' (a, b) { f (a.fst, f (a.snd, b)) }
- RList [Pair ['a]].FoldRight (ps, acc, f')
- | One (x, ps) => def f' (a, b) { f (a.fst, f (a.snd, b)) }
- f (x, RList [Pair ['a]].FoldRight (ps, acc, f'))
+ | Zero (ps) => RList [Pair ['a]].FoldRight (ps, acc, (a, b) => f (a.fst, f (a.snd, b)))
+ | One (x, ps) => f (x, RList [Pair ['a]].FoldRight (ps, acc, (a, b) => f (a.fst, f (a.snd, b))))
| Nil => acc
}
}
@@ -594,7 +590,7 @@
</returns>
*/
public static FromList (xs : list ['a], i : int) : RList ['a] {
- _FromList (xs, i, fun (l) { match (l) { | x :: tl => (x, tl) | [] => throw Exception ("Empty") } })
+ _FromList (xs, i, l => match (l) { | x :: tl => (x, tl) | [] => throw Exception ("Empty") })
}
/* An auxillary function used by FromList (xs, i).
More information about the svn
mailing list