ocaml: phase 5.1 lru_cache.ml baseline (cap=3 LRU, fingerprint 499)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Functional LRU cache via association-list ordered most-recent-first.
Get / put both:
  - find or remove the existing entry
  - cons the fresh (k, v) to the front
  - on put, trim the tail when over capacity

Sequence:
  put 1 100; put 2 200; put 3 300
  a = get 1  -> 100  (moves 1 to front)
  put 4 400          (evicts 2)
  b = get 2  -> -1   (no longer cached)
  c = get 3  -> 300
  d = get 1  -> 100
  a + b + c + d = 499

Tests `match … with (k', v) :: rest when k' = k -> …` tuple-cons
patterns with `when` guards, `function` keyword for arg-less
match, recursive find/remove/take over the same list.

Parser limit found: `match n, lst with` ad-hoc tuple-scrutinee is
not yet supported (got "expected op -> got op ,"); workaround
uses outer `if` plus inner match.

171 baseline programs total.
This commit is contained in:
2026-05-11 00:20:30 +00:00
parent 1d1c35a438
commit fd1f94f292
3 changed files with 63 additions and 0 deletions

View File

@@ -407,6 +407,17 @@ _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-11 Phase 5.1 — lru_cache.ml baseline (list-backed LRU
cache of capacity 3, fingerprint 100 + (-1) + 300 + 100 = 499).
Each `get` / `put` removes the existing entry then conses the
fresh one to the front; `put` evicts the tail when over capacity.
Tests `match … with [] -> … | (k', v) :: rest when k' = k -> …`
pattern matching with `when` guards over tuple-cons patterns,
`function` keyword for short scrutinee-free matches, recursive
`find` / `remove` / `take` over the same list. Note: parser does
not yet handle `match n, lst with` ad-hoc tuple-scrutinee (got
"expected op -> got op ,"); workaround uses an outer `if` then
inner `match lst with`. 171 baseline programs total.
- 2026-05-11 Phase 5.1 — convex_hull.ml baseline (Andrew's monotone
chain over 8 points → 5-vertex convex hull). Sorts points
lexicographically, then builds lower hull left-to-right and upper