haskell: Phase 12 — Data.Set full API (union/intersection/difference/isSubsetOf/filter/map/foldr/foldl)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 36s

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

View File

@@ -28,3 +28,35 @@
(define hk-set-null hk-map-null)
(define hk-set-to-asc-list hk-map-keys)
(define hk-set-to-list hk-map-keys)
(define
hk-set-from-list
(fn (xs) (reduce (fn (acc k) (hk-set-insert k acc)) hk-set-empty xs)))
(define
hk-set-union
(fn (a b) (hk-map-union-with (fn (x y) hk-set-unit) a b)))
(define
hk-set-intersection
(fn (a b) (hk-map-intersection-with (fn (x y) hk-set-unit) a b)))
(define hk-set-difference hk-map-difference)
(define
hk-set-is-subset-of
(fn (a b) (= (hk-map-size (hk-map-difference a b)) 0)))
(define
hk-set-filter
(fn (p s) (hk-map-filter-with-key (fn (k v) (p k)) s)))
(define hk-set-map (fn (f s) (hk-set-from-list (map f (hk-map-keys s)))))
(define
hk-set-foldr
(fn (f z s) (hk-map-foldr-with-key (fn (k v acc) (f k acc)) z s)))
(define
hk-set-foldl
(fn (f z s) (hk-map-foldl-with-key (fn (acc k v) (f acc k)) z s)))