Skip to content

Commit

Permalink
test: support OCaml < 4.12
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Apr 9, 2022
1 parent 5f31026 commit f1d6e34
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/ListAsBwd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@ let append xs ys = xs @ ys

let prepend xs ys = xs @ ys

let equal ~eq xs ys = L.equal ~eq (L.rev xs) (L.rev ys)

let compare ~cmp xs ys = L.compare ~cmp (L.rev xs) (L.rev ys)
let equal ~eq xs ys =
let rec go =
function
| [], [] -> true
| x::xs, y::ys -> eq x y && go (xs, ys)
| _ -> false
in
go (List.rev xs, List.rev ys)

let compare ~cmp xs ys =
let rec go =
function
| [], [] -> 0
| _::_, [] -> 1
| [], _::_ -> -1
| x::xs, y::ys ->
let c = cmp x y in
if c <> 0 then c else go (xs, ys)
in
go (List.rev xs, List.rev ys)

let iter ~f xs = L.iter ~f (L.rev xs)

Expand Down

0 comments on commit f1d6e34

Please sign in to comment.