diff --git a/lib/ocaml/baseline/atm.ml b/lib/ocaml/baseline/atm.ml new file mode 100644 index 00000000..cf8b66e0 --- /dev/null +++ b/lib/ocaml/baseline/atm.ml @@ -0,0 +1,17 @@ +type account = { mutable balance : int } + +exception Insufficient + +let withdraw acct amt = + if amt > acct.balance then raise Insufficient + else acct.balance <- acct.balance - amt + +let deposit acct amt = acct.balance <- acct.balance + amt + +;; + +let a = { balance = 100 } in +deposit a 50; +withdraw a 30; +try (withdraw a 200; -1) +with Insufficient -> a.balance diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index ccdfe1bb..1db31844 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -2,6 +2,7 @@ "ackermann.ml": 125, "anagram_check.ml": 2, "anagrams.ml": 3, + "atm.ml": 120, "bag.ml": 3, "bf_full.ml": 6, "bigint_add.ml": 28, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index b6486d70..accd5f67 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -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 — atm.ml baseline (mutable record + custom + exception + try/with, balance 120 after rollback). Models a bank + account: deposit/withdraw mutate the balance field; an over-draw + raises `Insufficient` which the caller catches and falls back to + the unchanged balance. Starting at 100, +50 = 150, -30 = 120, + attempted -200 throws and the handler returns 120. Combines + mutable record fields, user exception declaration, and + try-with-bare-pattern in a realistic micro-pattern. 59 baseline + programs total. - 2026-05-09 Phase 5.1 — bf_full.ml baseline (Brainfuck interpreter with `[`/`]` loops, `+++[.-]` → 3+2+1 = 6). Extends the iter-92 brainfuck.ml subset with bracket matching: `[` jumps past matching