diff --git a/lib/ocaml/baseline/csv.ml b/lib/ocaml/baseline/csv.ml new file mode 100644 index 00000000..56a023f3 --- /dev/null +++ b/lib/ocaml/baseline/csv.ml @@ -0,0 +1,12 @@ +let sum_second_col text = + let lines = String.split_on_char '\n' text in + List.fold_left (fun acc line -> + let fields = String.split_on_char ',' line in + if List.length fields >= 2 then + acc + int_of_string (List.nth fields 1) + else acc + ) 0 lines + +;; + +sum_second_col "a,1,extra\nb,2,extra\nc,3,extra\nd,4,extra" diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index fe38a370..343c9c3b 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -5,6 +5,7 @@ "caesar.ml": 215, "calc.ml": 13, "closures.ml": 315, + "csv.ml": 10, "exception_handle.ml": 4, "expr_eval.ml": 16, "factorial.ml": 3628800, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index d150efe9..29cfc0cf 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -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-09 Phase 5.1 — csv.ml baseline (split on '\n' then ',', + parse-int the second field, fold-left). Exercises char escapes + inside string literals, two-stage String.split_on_char, mixed + List.fold_left + int_of_string + List.nth. Sums column 2 of a + 4-row inline CSV → 1+2+3+4 = 10. 23 baseline programs total. - 2026-05-09 Phase 4 — polymorphic variants confirmation (+3 tests, 506 total). The tokenizer was already classifying `` `Tag `` as a ctor identical to a nominal one, but it had never been exercised by