haskell: reject untypeable programs — hk-typecheck + hk-run-typed (+9 tests, 464/464)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 46s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 22:32:18 +00:00
parent 68124adc3b
commit 2606b83920
5 changed files with 121 additions and 38 deletions

View File

@@ -790,3 +790,25 @@ negate x = 0 - x
(fn
(src)
(hk-deep-force (hk-eval (hk-core-expr src) (hk-dict-copy hk-env0)))))
(define
hk-typecheck
(fn
(prog)
(let
((results (hk-infer-prog prog (hk-type-env0))))
(let
((errors (filter (fn (r) (= (first r) "err")) results)))
(when (not (empty? errors)) (raise (nth (first errors) 1)))))))
(define
hk-run-typed
(fn
(src)
(let
((prog (hk-core src)))
(begin
(hk-typecheck prog)
(let
((env (hk-eval-program prog)))
(cond ((has-key? env "main") (get env "main")) (:else env)))))))