haskell: Phase 11 — Data.Map module wiring (import qualified ... as Map)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 44s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 11:26:44 +00:00
parent b0974b58c0
commit e1a020dc90
4 changed files with 95 additions and 3 deletions

View File

@@ -38,6 +38,7 @@ run_suite() {
(load "lib/haskell/runtime.sx")
(load "lib/haskell/match.sx")
(load "lib/haskell/eval.sx")
(load "lib/haskell/map.sx")
(load "lib/haskell/testlib.sx")
(epoch 2)
(load "$FILE")

View File

@@ -1023,6 +1023,68 @@
1))
env)))))
(define
hk-bind-data-map!
(fn
(env alias)
(let
((p (str alias ".")))
(begin
(dict-set! env (str p "empty") hk-map-empty)
(dict-set!
env
(str p "singleton")
(hk-mk-lazy-builtin
"Map.singleton"
(fn (k v) (hk-map-singleton (hk-force k) (hk-force v)))
2))
(dict-set!
env
(str p "insert")
(hk-mk-lazy-builtin
"Map.insert"
(fn
(k v m)
(hk-map-insert (hk-force k) (hk-force v) (hk-force m)))
3))
(dict-set!
env
(str p "lookup")
(hk-mk-lazy-builtin
"Map.lookup"
(fn (k m) (hk-map-lookup (hk-force k) (hk-force m)))
2))
(dict-set!
env
(str p "member")
(hk-mk-lazy-builtin
"Map.member"
(fn
(k m)
(hk-of-bool (hk-map-member (hk-force k) (hk-force m))))
2))
(dict-set!
env
(str p "size")
(hk-mk-lazy-builtin
"Map.size"
(fn (m) (hk-map-size (hk-force m)))
1))
(dict-set!
env
(str p "null")
(hk-mk-lazy-builtin
"Map.null"
(fn (m) (hk-of-bool (hk-map-null (hk-force m))))
1))
(dict-set!
env
(str p "delete")
(hk-mk-lazy-builtin
"Map.delete"
(fn (k m) (hk-map-delete (hk-force k) (hk-force m)))
2))))))
(define
hk-bind-decls!
(fn
@@ -1176,6 +1238,14 @@
inst-dict))))))
cons-list))
deriving-list)))))
((or (= (first d) ":import") (= (first d) "import"))
(let
((modname (nth d 2)) (as-name (nth d 3)))
(let
((alias (cond ((nil? as-name) "Map") (:else as-name))))
(cond
((= modname "Data.Map") (hk-bind-data-map! env alias))
(:else nil)))))
(:else nil)))
decls)
(let
@@ -1230,8 +1300,13 @@
(let
((env (hk-dict-copy hk-env0)))
(let
((decls (cond ((= (first ast) "program") (nth ast 1)) ((= (first ast) "module") (nth ast 4)) (:else (raise "eval-program: bad shape")))))
(hk-bind-decls! env decls))))))))
((imports (cond ((= (first ast) "module") (nth ast 3)) (:else (list))))
(decls
(cond
((= (first ast) "program") (nth ast 1))
((= (first ast) "module") (nth ast 4))
(:else (raise "eval-program: bad shape")))))
(begin (hk-bind-decls! env imports) (hk-bind-decls! env decls)))))))))
(define
hk-run

View File

@@ -55,6 +55,7 @@ for FILE in "${FILES[@]}"; do
(load "lib/haskell/runtime.sx")
(load "lib/haskell/match.sx")
(load "lib/haskell/eval.sx")
(load "lib/haskell/map.sx")
$INFER_LOAD
(load "lib/haskell/testlib.sx")
(epoch 2)
@@ -98,6 +99,7 @@ EPOCHS
(load "lib/haskell/runtime.sx")
(load "lib/haskell/match.sx")
(load "lib/haskell/eval.sx")
(load "lib/haskell/map.sx")
$INFER_LOAD
(load "lib/haskell/testlib.sx")
(epoch 2)