We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f31026 commit f1d6e34Copy full SHA for f1d6e34
1 file changed
test/ListAsBwd.ml
@@ -17,9 +17,26 @@ let append xs ys = xs @ ys
17
18
let prepend xs ys = xs @ ys
19
20
-let equal ~eq xs ys = L.equal ~eq (L.rev xs) (L.rev ys)
21
-
22
-let compare ~cmp xs ys = L.compare ~cmp (L.rev xs) (L.rev ys)
+let equal ~eq xs ys =
+ let rec go =
+ function
23
+ | [], [] -> true
24
+ | x::xs, y::ys -> eq x y && go (xs, ys)
25
+ | _ -> false
26
+ in
27
+ go (List.rev xs, List.rev ys)
28
+
29
+let compare ~cmp xs ys =
30
31
32
+ | [], [] -> 0
33
+ | _::_, [] -> 1
34
+ | [], _::_ -> -1
35
+ | x::xs, y::ys ->
36
+ let c = cmp x y in
37
+ if c <> 0 then c else go (xs, ys)
38
39
40
41
let iter ~f xs = L.iter ~f (L.rev xs)
42
0 commit comments