haskell: thunks + force, app args become lazy (+6 tests, 333/333)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 23:22:21 +00:00
parent fba92c2b69
commit 0e53e88b02
4 changed files with 222 additions and 94 deletions

View File

@@ -6,7 +6,7 @@
hk-prog-val
(fn
(src name)
(get (hk-eval-program (hk-core src)) name)))
(hk-deep-force (get (hk-eval-program (hk-core src)) name))))
;; ── Literals ──
(hk-test "int literal" (hk-eval-expr-source "42") 42)
@@ -230,6 +230,46 @@
"if True then 1 else error \"unreachable\"")
1)
;; ── Laziness: app args evaluate only when forced ──
(hk-test
"second arg never forced"
(hk-eval-expr-source
"(\\x y -> x) 1 (error \"never\")")
1)
(hk-test
"first arg never forced"
(hk-eval-expr-source
"(\\x y -> y) (error \"never\") 99")
99)
(hk-test
"constructor argument is lazy under wildcard pattern"
(hk-eval-expr-source
"case Just (error \"deeply\") of Just _ -> 7 ; Nothing -> 0")
7)
(hk-test
"lazy: const drops its second argument"
(hk-prog-val
"const x y = x\nresult = const 5 (error \"boom\")"
"result")
5)
(hk-test
"lazy: head ignores tail"
(hk-prog-val
"myHead (x:_) = x\nresult = myHead (1 : (error \"tail\") : [])"
"result")
1)
(hk-test
"lazy: Just on undefined evaluates only on force"
(hk-prog-val
"wrapped = Just (error \"oh no\")\nresult = case wrapped of Just _ -> True ; Nothing -> False"
"result")
(list "True"))
;; ── not / id built-ins ──
(hk-test "not True" (hk-eval-expr-source "not True") (list "False"))
(hk-test "not False" (hk-eval-expr-source "not False") (list "True"))