ocaml: phase 5.1 validate.ml baseline (Either-based validation, 3 errs * 100 + 117 = 417)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

validate_int returns Left msg on empty / non-digit, Right
(int_of_string s) on a digit-only string. process folds inputs with a
tuple accumulator (errs, sum), branching on the result.

  ['12'; 'abc'; '5'; ''; '100'; 'x']
  -> 3 errors (abc, '', x), valid sum = 12+5+100 = 117
  -> errs * 100 + sum = 417

Exercises:
  - Either constructors used bare (Left/Right without 'Either.'
    qualification)
  - char range comparison: c >= '0' && c <= '9'
  - tuple-pattern destructuring on let-binding (iter 98)
  - recursive helper defined inside if-else
  - List.fold_left with tuple accumulator

36 baseline programs total.
This commit is contained in:
2026-05-09 08:11:07 +00:00
parent 5c70747ac7
commit 1a828d5b9f
3 changed files with 34 additions and 0 deletions

View File

@@ -407,6 +407,15 @@ _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 — validate.ml baseline (Either-based input
validation, 3 errors × 100 + 117 sum = 417). validate_int returns
`Left msg` on empty / non-digit, `Right (int_of_string s)` on a
digit-only string. process folds inputs with a tuple accumulator
`(errs, sum)`, branching on the result. ["12"; "abc"; "5"; "";
"100"; "x"] → (3, 117) → 417. Exercises Either constructors used
bare (no qualification), char range comparison, tuple-pattern
destructuring on let-binding, recursive helper inside if-else. 36
baseline programs total.
- 2026-05-09 Phase 5.1 — word_freq.ml baseline (Map.Make on String,
count distinct words → 8). Defines a StringOrd module + applies
Map.Make to it. Folds the input through SMap.find_opt + SMap.add to