ocaml: phase 5.1 zerosafe.ml baseline (Option-chained safe division, sum = 28)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
safe_div returns None on division by zero; safe_chain stitches two
divisions, propagating None on either failure:
let safe_div a b =
if b = 0 then None else Some (a / b)
let safe_chain a b c =
match safe_div a b with
| None -> None
| Some q -> safe_div q c
Test:
safe_chain 100 2 5 = Some 10
safe_chain 100 0 5 = None -> -1
safe_chain 50 5 0 = None -> -1
safe_chain 1000 10 5 = Some 20
10 - 1 - 1 + 20 = 28
Tests Option chaining + match-on-result with sentinel default.
Demonstrates the canonical 'fail-early on None' pattern.
129 baseline programs total.
This commit is contained in:
@@ -407,6 +407,11 @@ _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-10 Phase 5.1 — zerosafe.ml baseline (Option-chained safe
|
||||
division, sum 10 + (-1) + (-1) + 20 = 28). safe_div returns None
|
||||
on division by zero; safe_chain stitches two divisions, propagating
|
||||
None on either failure. Tests Option chaining + match-on-result
|
||||
with sentinel default. 129 baseline programs total.
|
||||
- 2026-05-10 Phase 5.1 — number_words.ml baseline (letter count of
|
||||
numbers 1-19 spelled out = 106). 19-arm match dispatch returning
|
||||
the English word for each number. Sums lengths over 1..19. Real
|
||||
|
||||
Reference in New Issue
Block a user