[MLton-commit] r5534
Vesa Karvonen
vesak at mlton.org
Sat Apr 21 09:33:33 PDT 2007
Simplified and optimized nubByEq. The optimization is that equality tests
are only made against the accumulated list of unique elements.
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/list.sml
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/list.sml
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/list.sml 2007-04-19 17:44:27 UTC (rev 5533)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/sequence/list.sml 2007-04-21 16:33:32 UTC (rev 5534)
@@ -116,18 +116,7 @@
in
fun divideByEq eq xs = divideByEqTail eq xs []
end
-
- local
- fun nubByEqTail eq xs accum =
- case xs
- of [] => accum
- | x::xs' =>
- if exists (Fn.curry eq x) xs' then
- nubByEqTail eq xs' accum
- else
- nubByEqTail eq xs' (x::accum)
- in
- fun nubByEq eq xs = nubByEqTail eq (rev xs) []
- end
-
+ fun nubByEq eq =
+ rev o foldl (fn (x, ys) =>
+ if exists (Fn.curry eq x) ys then ys else x::ys) []
end
More information about the MLton-commit
mailing list