haskell: real IO monad — putStrLn/print/putStr + hk-run-io (+10 tests, 575/575)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 20s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 13:10:42 +00:00
parent 1c45262577
commit 578e54f06d
3 changed files with 101 additions and 2 deletions

View File

@@ -683,7 +683,41 @@
(dict-set! env "quot" (hk-make-binop-builtin "quot" "quot"))
(dict-set! env "show" (hk-mk-lazy-builtin "show" hk-show-val 1))
(hk-load-into! env hk-prelude-src)
env)))
(do
(dict-set!
env
"putStrLn"
(hk-mk-lazy-builtin
"putStrLn"
(fn
(s)
(do
(append! hk-io-lines (hk-force s))
(list "IO" (list "Tuple"))))
1))
(dict-set!
env
"putStr"
(hk-mk-lazy-builtin
"putStr"
(fn
(s)
(do
(append! hk-io-lines (hk-force s))
(list "IO" (list "Tuple"))))
1))
(dict-set!
env
"print"
(hk-mk-lazy-builtin
"print"
(fn
(x)
(do
(append! hk-io-lines (hk-show-val x))
(list "IO" (list "Tuple"))))
1))
env))))
;; Eagerly build the Prelude env once at load time; each call to
;; hk-eval-expr-source copies it instead of re-parsing the whole Prelude.
@@ -905,6 +939,12 @@
((env (hk-eval-program (hk-core src))))
(cond ((has-key? env "main") (get env "main")) (:else env)))))
(define hk-io-lines (list))
(define
hk-run-io
(fn (src) (do (set! hk-io-lines (list)) (hk-run src) hk-io-lines)))
(define hk-env0 (hk-init-env))
(define