haskell: Phase 9 — partial fns proper error messages (head []/tail []/fromJust Nothing) (+5 tests, 64/64)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m5s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 03:31:20 +00:00
parent 51f57aa2fa
commit 5f758d27c1
3 changed files with 43 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@@ -259,6 +259,36 @@
(hk-deep-force (hk-run "main = if True then 42 else undefined"))
42)
(hk-test
"head []: raises Prelude.head: empty list"
(guard
(e (true (>= (index-of e "Prelude.head: empty list") 0)))
(begin (hk-deep-force (hk-run "main = head []")) false))
true)
(hk-test
"tail []: raises Prelude.tail: empty list"
(guard
(e (true (>= (index-of e "Prelude.tail: empty list") 0)))
(begin (hk-deep-force (hk-run "main = tail []")) false))
true)
;; ── not / id built-ins ──
(hk-test
"fromJust Nothing: raises Maybe.fromJust: Nothing"
(guard
(e (true (>= (index-of e "Maybe.fromJust: Nothing") 0)))
(begin (hk-deep-force (hk-run "main = fromJust Nothing")) false))
true)
(hk-test
"fromJust (Just 5) = 5"
(hk-deep-force (hk-run "main = fromJust (Just 5)"))
5)
(hk-test
"head [42] = 42 (still works for non-empty)"
(hk-deep-force (hk-run "main = head [42]"))
42)
(hk-test
"second arg never forced"
(hk-eval-expr-source "(\\x y -> x) 1 (error \"never\")")
@@ -269,16 +299,17 @@
(hk-eval-expr-source "(\\x y -> y) (error \"never\") 99")
99)
;; ── not / id built-ins ──
(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

View File

@@ -128,7 +128,7 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
the tag has to live in a string prefix rather than as the head of a list.
Catchers use `(index-of e "hk-error: ")` to detect.
- [x] `undefined :: a` = `error "Prelude.undefined"`.
- [ ] Partial functions emit proper error messages: `head []`
- [x] Partial functions emit proper error messages: `head []`
`"Prelude.head: empty list"`, `tail []``"Prelude.tail: empty list"`,
`fromJust Nothing``"Maybe.fromJust: Nothing"`.
- [ ] Top-level `hk-run-io` catches `hk-error` tag and returns it as a tagged
@@ -293,6 +293,15 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
_Newest first._
**2026-05-07** — Phase 9 partial functions emit proper error messages:
- Added empty-list catch clauses to `head`, `tail` in the prelude. Added
`fromJust`, `fromMaybe`, `isJust`, `isNothing` (the last three were missing).
`fromJust Nothing` raises `"Maybe.fromJust: Nothing"`. Multi-clause dispatch
tries the constructor pattern first, then falls through to the empty-list /
Nothing error clause.
- 5 new tests in `tests/eval.sx`. Suite is 64/64. Verified no regressions in
match, stdlib, fib, quicksort, program-maybe.
**2026-05-07** — Phase 9 `undefined = error "Prelude.undefined"` + lazy CAFs:
- Added `undefined = error "Prelude.undefined"` to `hk-prelude-src`. Without
any other change this raised at prelude-load time because `hk-bind-decls!`