ocaml: phase 5.1 bag.ml baseline + String.equal/compare/cat/empty (+3 tests, 579 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

bag.ml: split a sentence on spaces, count each word in a Hashtbl,
return the maximum count via Hashtbl.fold.

  count_words 'the quick brown fox jumps over the lazy dog the fox'
  -> Hashtbl with 'the' = 3 as the max
  -> 3

Exercises String.split_on_char + Hashtbl.find_opt/replace +
Hashtbl.fold (k v acc -> ...). Together with frequency.ml from
iter 84 we now have two Hashtbl-counting baselines exercising
slightly different idioms. 29 baseline programs total.

String additions:
  equal a b      = a = b
  compare a b    = -1 / 0 / 1 via host < / >
  cat a b        = a ^ b
  empty          = '' (constant)
This commit is contained in:
2026-05-09 06:15:03 +00:00
parent 7ca5bfbb70
commit ddd1e40d00
5 changed files with 45 additions and 0 deletions

View File

@@ -407,6 +407,14 @@ _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 — bag.ml baseline + String.equal/compare/cat/
empty (+3 tests, 579 total). bag.ml: split a sentence on spaces,
count word frequency in a Hashtbl, return the maximum count.
Sentence "the quick brown fox jumps over the lazy dog the fox" has
"the"×3 as the most frequent → 3. Exercises String.split_on_char +
Hashtbl.find_opt/replace + Hashtbl.fold over (k, v) tuples. 29
baseline programs total. String additions: equal, compare (via host
`<`/`>`), cat (alias of `^`), empty.
- 2026-05-09 Phase 5.1 — fraction.ml baseline (rational arithmetic
via record + gcd canonicalization). Defines `type frac = { num;
den }`, `make` that reduces via gcd and forces den > 0, `add` and