haskell: Phase 15 — IORef (5 ops + module wiring + ioref.sx 13/13 + counter.hs 7/7 + accumulate.hs 8/8)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s

hk-bind-data-ioref! registers newIORef / readIORef / writeIORef /
modifyIORef / modifyIORef' under the import alias (default IORef).
Representation: dict {"hk-ioref" true "hk-value" v} allocated inside IO.
modifyIORef' uses hk-deep-force on the new value before write.

Side-effect: fixed pre-existing bug in import handler — modname was
reading (nth d 1) (the qualified flag) instead of (nth d 2). All
'import qualified … as Foo' paths were silently no-ops; map.sx unit
suite jumps from 22→26 passing.

Conformance now 33/34 programs, 266/269 tests (only pre-existing
palindrome.hs 9/12 still failing on string-as-list reversal, present
on prior commit).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-07 18:49:55 +00:00
parent f26f25f146
commit f1fea0f2f1
8 changed files with 379 additions and 21 deletions

View File

@@ -1242,6 +1242,78 @@
(hk-of-bool (hk-set-is-subset-of (hk-force a) (hk-force b))))
2))))))
(define
hk-bind-data-ioref!
(fn
(env alias)
(let
((p (str alias ".")))
(begin
(dict-set!
env
(str p "newIORef")
(hk-mk-lazy-builtin
"IORef.newIORef"
(fn
(v)
(let
((ref (dict)))
(begin
(dict-set! ref "hk-ioref" true)
(dict-set! ref "hk-value" v)
(list "IO" ref))))
1))
(dict-set!
env
(str p "readIORef")
(hk-mk-lazy-builtin
"IORef.readIORef"
(fn (r) (list "IO" (get (hk-force r) "hk-value")))
1))
(dict-set!
env
(str p "writeIORef")
(hk-mk-lazy-builtin
"IORef.writeIORef"
(fn
(r v)
(begin
(dict-set! (hk-force r) "hk-value" v)
(list "IO" (list "Tuple"))))
2))
(dict-set!
env
(str p "modifyIORef")
(hk-mk-lazy-builtin
"IORef.modifyIORef"
(fn
(r f)
(let
((ref (hk-force r)))
(begin
(dict-set!
ref
"hk-value"
(hk-apply f (get ref "hk-value")))
(list "IO" (list "Tuple")))))
2))
(dict-set!
env
(str p "modifyIORef'")
(hk-mk-lazy-builtin
"IORef.modifyIORef'"
(fn
(r f)
(let
((ref (hk-force r)))
(begin
(dict-set!
ref
"hk-value"
(hk-deep-force (hk-apply f (get ref "hk-value"))))
(list "IO" (list "Tuple")))))
2))))))
(define
hk-bind-decls!
(fn
@@ -1450,10 +1522,12 @@
(let
((modname (nth d 2)) (as-name (nth d 3)))
(let
((alias (cond ((not (nil? as-name)) as-name) ((= modname "Data.Map") "Map") ((= modname "Data.Set") "Set") (:else modname))))
((alias (cond ((not (nil? as-name)) as-name) ((= modname "Data.Map") "Map") ((= modname "Data.Set") "Set") ((= modname "Data.IORef") "IORef") (:else modname))))
(cond
((= modname "Data.Map") (hk-bind-data-map! env alias))
((= modname "Data.Set") (hk-bind-data-set! env alias))
((= modname "Data.IORef")
(hk-bind-data-ioref! env alias))
(:else nil)))))
(:else nil)))
decls)