ocaml: phase 4 'fun (a, b) -> body' tuple-param destructuring (+4 tests, 553 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s
parse-fun's collect-params now detects '(IDENT, ...)' as a
tuple-pattern parameter (lookahead at peek-tok-at 1/2 distinguishes
from '(x : T)' and '()' cases that try-consume-param! already
handles). For each tuple param it:
1. parse-pattern to get the full pattern AST
2. generate a synthetic __pat_N name as the actual fun parameter
3. push (synth_name, pattern) onto tuple-binds
After parsing the body, wraps it innermost-first with one
'match __pat_N with PAT -> ...' per tuple-param. The user-visible
result is a (:fun (params...) body) where params are all simple
names but the body destructures.
Also retroactively simplifies Hashtbl.keys/values from
'fun pair -> match pair with (k, _) -> k' to plain
'fun (k, _) -> k', closing the iteration-99 workaround.
(fun (a, b) -> a + b) (3, 7) = 10
List.map (fun (a, b) -> a * b)
[(1, 2); (3, 4); (5, 6)] = [2; 12; 30]
List.map (fun (k, _) -> k)
[("a", 1); ("b", 2)] = ["a"; "b"]
(fun a (b, c) d -> a + b + c + d) 1 (2, 3) 4 = 10
This commit is contained in:
@@ -407,6 +407,16 @@ _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 4 — `fun (a, b) -> body` tuple-param destructuring
|
||||
(+4 tests, 553 total). parse-fun's collect-params now detects
|
||||
`(IDENT, ...)` (lookahead at peek-tok-at 1/2 to distinguish from
|
||||
`(x : T)` and `()` cases), generates a synthetic `__pat_N` name as
|
||||
the actual fun param, and remembers the pattern in tuple-binds.
|
||||
After parsing the body, wraps it innermost-first with one
|
||||
`match __pat_N with PAT -> ...` per tuple-param. Also retroactively
|
||||
simplifies `Hashtbl.keys`/`values` from
|
||||
`fun pair -> match pair with (k, _) -> k` to plain
|
||||
`fun (k, _) -> k`.
|
||||
- 2026-05-09 Phase 6 — Random module (LCG-based, deterministic) (+4
|
||||
tests, 549 total). Linear-congruential PRNG with mutable seed
|
||||
(`_state` ref). API: init, self_init, int, bool, float, bits.
|
||||
|
||||
Reference in New Issue
Block a user