haskell: seq + deepseq via lazy-builtin flag (+9 tests, 368/368)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 00:28:19 +00:00
parent cc5315a5e6
commit 04a25d17d0
3 changed files with 139 additions and 7 deletions

View File

@@ -79,7 +79,7 @@ Key mappings:
- [x] `force` = SX eval-thunk-to-WHNF primitive
- [x] Pattern match forces scrutinee before matching
- [x] Infinite structures: `repeat x`, `iterate f x`, `[1..]`, Fibonacci stream (sieve deferred — needs lazy `++` and is exercised under `Classic programs`)
- [ ] `seq`, `deepseq` from Prelude
- [x] `seq`, `deepseq` from Prelude
- [ ] Do-notation for a stub `IO` monad (just threading, no real side effects yet)
- [ ] Classic programs in `lib/haskell/tests/programs/`:
- [ ] `fib.hs` — infinite Fibonacci stream
@@ -114,6 +114,22 @@ Key mappings:
_Newest first._
- **2026-04-25** — Phase 3 `seq` + `deepseq`. Built-ins were strict
in all args by default (every collected thunk forced before
invoking the underlying SX fn) — that defeats `seq`'s purpose,
which is strict in its first argument and lazy in its second.
Added a tiny `lazy` flag on the builtin record (set by a new
`hk-mk-lazy-builtin` constructor) and routed `hk-apply-builtin`
to skip the auto-force when the flag is true. `seq a b` calls
`hk-force a` then returns `b` unchanged so its laziness is
preserved; `deepseq` does the same with `hk-deep-force`. 9 new
tests in `lib/haskell/tests/seq.sx` cover primitive, computed,
and let-bound first args, deepseq on a list / `Just` /
tuple, seq inside arithmetic, seq via a fun-clause, and
`[seq 1 10, seq 2 20]` to confirm seq composes inside list
literals. The lazy-when-unused negative case is also tested:
`let x = error "never" in 42 == 42`. 368/368 green.
- **2026-04-24** — Phase 3 infinite structures + Prelude. Two
evaluator changes turn the lazy primitives into a working
language: