haskell: Phase 12 — Data.Set skeleton (wraps Data.Map with unit values)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 35s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 11:37:39 +00:00
parent e6d6273265
commit 208953667b
2 changed files with 39 additions and 2 deletions

30
lib/haskell/set.sx Normal file
View File

@@ -0,0 +1,30 @@
;; set.sx — Phase 12 Data.Set: wraps Data.Map with unit values.
;;
;; A Set is a Map from key to (). All set operations delegate to the map
;; ops, ignoring the value side. Storage representation matches Data.Map:
;;
;; Empty → ("Map-Empty")
;; Node → ("Map-Node" key () left right size)
;;
;; Tradeoff: trivial maintenance burden, slight overhead per node from
;; the unused value slot. Faster path forward than re-implementing the
;; weight-balanced BST.
;;
;; Functions live in this file; the Haskell-level `import Data.Set` /
;; `import qualified Data.Set as Set` wiring (next Phase 12 box) binds
;; them under the chosen alias.
(define hk-set-unit (list "Tuple"))
(define hk-set-empty hk-map-empty)
(define hk-set-singleton (fn (k) (hk-map-singleton k hk-set-unit)))
(define hk-set-insert (fn (k s) (hk-map-insert k hk-set-unit s)))
(define hk-set-delete hk-map-delete)
(define hk-set-member hk-map-member)
(define hk-set-size hk-map-size)
(define hk-set-null hk-map-null)
(define hk-set-to-asc-list hk-map-keys)
(define hk-set-to-list hk-map-keys)

View File

@@ -203,9 +203,9 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
### Phase 12 — Data.Set
- [ ] Implement `Data.Set` in `lib/haskell/set.sx`. Use a standalone
- [x] Implement `Data.Set` in `lib/haskell/set.sx`. Use a standalone
weight-balanced BST (same structure as Map but no value field) or wrap
`Data.Map` with unit values.
`Data.Map` with unit values. _Chose the wrapper approach: Set k = Map k ()._
- [ ] API: `empty`, `singleton`, `insert`, `delete`, `member`, `fromList`,
`toList`, `toAscList`, `size`, `null`, `union`, `intersection`, `difference`,
`isSubsetOf`, `filter`, `map`, `foldr`, `foldl'`.
@@ -307,6 +307,13 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
_Newest first._
**2026-05-07** — Phase 12 Data.Set skeleton (wraps Data.Map with unit values):
- New `lib/haskell/set.sx`. `hk-set-empty/singleton/insert/delete/member/
size/null/to-list` all delegate to the corresponding `hk-map-*`. Storage
representation matches Map nodes; values are always `("Tuple")` (unit).
This trades a small per-node memory overhead for a one-line implementation
of every set primitive — full BST balancing comes for free. Spot-checked.
**2026-05-07** — Phase 11 conformance: wordfreq.hs (7/7) + mapgraph.hs (6/6) → Phase 11 complete:
- Extended `hk-bind-data-map!` with `Map.insertWith`, `Map.adjust`, and
`Map.findWithDefault` so the conformance programs have what they need.