ocaml: phase 6 List.sort + compare (+7 tests, 339 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s

compare is a host builtin returning -1/0/1 (Stdlib.compare semantics)
deferred to host SX </>. List.sort is insertion-sort in OCaml: O(n²)
but works correctly. List.stable_sort = sort.

Tested: ascending int sort, descending via custom comparator (b - a),
empty list, string sort.
This commit is contained in:
2026-05-08 12:59:50 +00:00
parent 812aa75d43
commit 202ea9cf5f
4 changed files with 54 additions and 2 deletions

View File

@@ -242,8 +242,8 @@ SX CEK evaluator (both JS and OCaml hosts)
- [~] `List`: `map`, `filter`, `fold_left`, `fold_right`, `length`, `rev`,
`append`, `iter`, `for_all`, `exists`, `mem`, `nth`, `hd`, `tl`,
`rev_append`, `concat`/`flatten`, `init`, `iteri`, `mapi`, `find`,
`find_opt`, `assoc`, `assoc_opt`, `partition`. _(Pending:
sort/stable_sort, combine, split.)_
`find_opt`, `assoc`, `assoc_opt`, `partition`, `sort`,
`stable_sort` (insertion sort, O(n²)). _(Pending: combine, split.)_
- [~] `Option`: `map`, `bind`, `value`, `get`, `is_none`, `is_some`,
`iter`, `fold`, `to_list`. _(Pending: join/to_result.)_
- [~] `Result`: `map`, `bind`, `is_ok`, `is_error`, `get_ok`,
@@ -365,6 +365,11 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
_Newest first._
- 2026-05-08 Phase 6 — `List.sort` + polymorphic `compare` (+7 tests,
339 total). `compare` is a host primitive that returns -1/0/1 like
Stdlib.compare, defers to host SX `<`/`>`. `List.sort` is implemented
in OCaml as insertion sort: O(n²) but correct, and passes all tests
including descending custom comparator and string sort.
- 2026-05-08 Phase 6 — `Hashtbl` (+6 tests, 332 total). Backing store is
a one-element list cell holding a SX dict; keys are coerced to
strings via `str` so any value type can serve as a key. API: create,