ocaml: phase 5.1 safe_div.ml baseline + Result.equal/compare/iter_error (+3 tests, 592 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s
safe_div.ml: integer division returning Result. Sum-safe folds pairs,
skipping the Error branches.
[(10,2); (20,4); (30,0); (50,5)] -> 5 + 5 + 0 + 10 = 20
Result module additions (mirroring real OCaml's signatures):
equal eq_ok eq_err a b
compare cmp_ok cmp_err a b Ok < Error (i.e. Ok x compared to
Error e returns -1)
iter_error f r
Result.equal (=) (=) (Ok 1) (Ok 1) = true
Result.compare compare compare (Ok 5) (Ok 3) = 1
Result.compare compare compare (Ok 1) (Error _) = -1
30 baseline programs total.
This commit is contained in:
@@ -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 5.1 — safe_div.ml baseline + Result.equal /
|
||||
compare / iter_error (+3 tests, 592 total). safe_div divides only
|
||||
if divisor non-zero, returns `Error "..."` otherwise. sum_safe folds
|
||||
pairs with `Ok q -> acc+q | Error _ -> acc`.
|
||||
`[(10,2);(20,4);(30,0);(50,5)]` → 5+5+0+10 = 20. Result additions:
|
||||
equal/compare take separate eq/cmp for Ok and Error sides; Ok < Error
|
||||
(-1) and Error > Ok (1). 30 baseline programs total.
|
||||
- 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.
|
||||
|
||||
Reference in New Issue
Block a user