ocaml: phase 6 List.equal / List.compare (+5 tests, 589 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

Both take an inner predicate / comparator and walk both lists in
lockstep:

  equal eq a b     short-circuits on first mismatch
  compare cmp a b  -1 if a is a strict prefix
                    1 if b is
                    0 if both empty
                    otherwise first non-zero element comparison

Mirrors real OCaml's signatures.

  List.equal (=) [1;2;3] [1;2;3]            = true
  List.equal (=) [1;2;3] [1;2;4]            = false
  List.compare compare [1;2;3] [1;2;4]      = -1
  List.compare compare [1;2] [1;2;3]        = -1
  List.compare compare [] []                = 0
This commit is contained in:
2026-05-09 06:35:42 +00:00
parent 4d32c80a99
commit 98ba772acd
3 changed files with 44 additions and 0 deletions

View File

@@ -407,6 +407,13 @@ _Newest first._
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
'a tree`) with insert + in-order traversal. Tests parametric ADT,
recursive match, List.append, List.fold_left.
- 2026-05-09 Phase 6 — List.equal / List.compare (+5 tests, 589
total). Both take an inner predicate / comparator and walk both
lists in lockstep. equal short-circuits on first mismatch.
compare returns -1 if a is a strict prefix, 1 if b is, 0 if both
empty, otherwise the first non-zero element comparison. Mirrors
real OCaml's signatures: `List.equal eq a b`, `List.compare cmp
a b`.
- 2026-05-09 Phase 6 — Bool module + Option.equal / Option.compare
(+5 tests, 584 total). Bool: equal, compare (false < true via if
ladder), to_string, of_string, not_, to_int. Option additions