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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 11:41:16 +00:00
parent 34513908df
commit 7ce0c797f3
4 changed files with 104 additions and 2 deletions

View File

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

View File

@@ -1123,6 +1123,89 @@
(:else (hk-force d)))))
3))))))
(define
hk-bind-data-set!
(fn
(env alias)
(let
((p (str alias ".")))
(begin
(dict-set! env (str p "empty") hk-set-empty)
(dict-set!
env
(str p "singleton")
(hk-mk-lazy-builtin
"Set.singleton"
(fn (k) (hk-set-singleton (hk-force k)))
1))
(dict-set!
env
(str p "insert")
(hk-mk-lazy-builtin
"Set.insert"
(fn (k s) (hk-set-insert (hk-force k) (hk-force s)))
2))
(dict-set!
env
(str p "delete")
(hk-mk-lazy-builtin
"Set.delete"
(fn (k s) (hk-set-delete (hk-force k) (hk-force s)))
2))
(dict-set!
env
(str p "member")
(hk-mk-lazy-builtin
"Set.member"
(fn
(k s)
(hk-of-bool (hk-set-member (hk-force k) (hk-force s))))
2))
(dict-set!
env
(str p "size")
(hk-mk-lazy-builtin
"Set.size"
(fn (s) (hk-set-size (hk-force s)))
1))
(dict-set!
env
(str p "null")
(hk-mk-lazy-builtin
"Set.null"
(fn (s) (hk-of-bool (hk-set-null (hk-force s))))
1))
(dict-set!
env
(str p "union")
(hk-mk-lazy-builtin
"Set.union"
(fn (a b) (hk-set-union (hk-force a) (hk-force b)))
2))
(dict-set!
env
(str p "intersection")
(hk-mk-lazy-builtin
"Set.intersection"
(fn (a b) (hk-set-intersection (hk-force a) (hk-force b)))
2))
(dict-set!
env
(str p "difference")
(hk-mk-lazy-builtin
"Set.difference"
(fn (a b) (hk-set-difference (hk-force a) (hk-force b)))
2))
(dict-set!
env
(str p "isSubsetOf")
(hk-mk-lazy-builtin
"Set.isSubsetOf"
(fn
(a b)
(hk-of-bool (hk-set-is-subset-of (hk-force a) (hk-force b))))
2))))))
(define
hk-bind-decls!
(fn
@@ -1280,9 +1363,15 @@
(let
((modname (nth d 2)) (as-name (nth d 3)))
(let
((alias (cond ((nil? as-name) "Map") (:else as-name))))
((alias
(cond
((not (nil? as-name)) as-name)
((= modname "Data.Map") "Map")
((= modname "Data.Set") "Set")
(:else modname))))
(cond
((= modname "Data.Map") (hk-bind-data-map! env alias))
((= modname "Data.Set") (hk-bind-data-set! env alias))
(:else nil)))))
(:else nil)))
decls)

View File

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

View File

@@ -209,7 +209,7 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
- [x] API: `empty`, `singleton`, `insert`, `delete`, `member`, `fromList`,
`toList`, `toAscList`, `size`, `null`, `union`, `intersection`, `difference`,
`isSubsetOf`, `filter`, `map`, `foldr`, `foldl'`.
- [ ] Module wiring: `import Data.Set` / `import qualified Data.Set as Set`.
- [x] Module wiring: `import Data.Set` / `import qualified Data.Set as Set`.
- [ ] Unit tests in `lib/haskell/tests/set.sx` (≥ 15 tests: empty, insert,
member hit/miss, delete, fromList deduplication, union, intersection,
difference, isSubsetOf).
@@ -307,6 +307,16 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
_Newest first._
**2026-05-07** — Phase 12 module wiring: `import Data.Set`:
- New `hk-bind-data-set!` registers `Set.empty/singleton/insert/delete/
member/size/null/union/intersection/difference/isSubsetOf` as Haskell
builtins.
- Import handler now dispatches on modname: `Data.Map` → `hk-bind-data-map!`,
`Data.Set` → `hk-bind-data-set!`. Default alias is now derived from the
modname suffix instead of being hardcoded `Map` (was a bug for `Data.Set`).
- `test.sh` and `conformance.sh` load `set.sx` after `map.sx`.
- Verified `Set.size`, `Set.member`, `Set.union`, `Set.insert` from Haskell.
**2026-05-07** — Phase 12 Data.Set full API:
- Added `from-list`/`union`/`intersection`/`difference`/`is-subset-of`/
`filter`/`map`/`foldr`/`foldl` — all delegate to the corresponding