diff --git a/lib/haskell/map.sx b/lib/haskell/map.sx index cc30f288..da9671d8 100644 --- a/lib/haskell/map.sx +++ b/lib/haskell/map.sx @@ -274,3 +274,49 @@ (hk-map-left m) (hk-map-delete k (hk-map-right m)))) (:else (hk-map-glue (hk-map-left m) (hk-map-right m))))))))) + +(define + hk-map-from-list + (fn + (pairs) + (reduce + (fn (acc p) (hk-map-insert (first p) (nth p 1) acc)) + hk-map-empty + pairs))) + +(define + hk-map-to-asc-list + (fn + (m) + (cond + ((hk-map-empty? m) (list)) + (:else + (append + (hk-map-to-asc-list (hk-map-left m)) + (cons + (list (hk-map-key m) (hk-map-val m)) + (hk-map-to-asc-list (hk-map-right m)))))))) + +(define hk-map-to-list hk-map-to-asc-list) + +(define + hk-map-keys + (fn + (m) + (cond + ((hk-map-empty? m) (list)) + (:else + (append + (hk-map-keys (hk-map-left m)) + (cons (hk-map-key m) (hk-map-keys (hk-map-right m)))))))) + +(define + hk-map-elems + (fn + (m) + (cond + ((hk-map-empty? m) (list)) + (:else + (append + (hk-map-elems (hk-map-left m)) + (cons (hk-map-val m) (hk-map-elems (hk-map-right m)))))))) diff --git a/plans/haskell-completeness.md b/plans/haskell-completeness.md index ea524e0d..c06cded0 100644 --- a/plans/haskell-completeness.md +++ b/plans/haskell-completeness.md @@ -184,7 +184,7 @@ No OCaml changes are needed. The view type is fully representable as an SX dict. Leaf: `("Map-Empty")`. - [x] Core operations: `empty`, `singleton`, `insert`, `lookup`, `delete`, `member`, `size`, `null`. -- [ ] Bulk operations: `fromList`, `toList`, `toAscList`, `keys`, `elems`. +- [x] Bulk operations: `fromList`, `toList`, `toAscList`, `keys`, `elems`. - [ ] Combining: `unionWith`, `intersectionWith`, `difference`. - [ ] Transforming: `foldlWithKey`, `foldrWithKey`, `mapWithKey`, `filterWithKey`. - [ ] Updating: `adjust`, `insertWith`, `insertWithKey`, `alter`. @@ -304,6 +304,14 @@ No OCaml changes are needed. The view type is fully representable as an SX dict. _Newest first._ +**2026-05-07** — Phase 11 bulk operations (fromList/toList/toAscList/keys/elems): +- `hk-map-from-list` uses SX `reduce` — left-to-right, so duplicates resolve + with last-wins (matches GHC `fromList`). `to-asc-list` is in-order recursive + traversal returning `(list (list k v) ...)`. `to-list` aliases `to-asc-list`. + `keys` and `elems` are similar in-order extracts. All take SX-level pairs; + the Haskell-layer wiring (next iterations) translates Haskell cons + tuple + representations. + **2026-05-07** — Phase 11 core operations on `Data.Map` BST: - Added `hk-map-singleton`, `hk-map-insert`, `hk-map-lookup`, `hk-map-delete`, `hk-map-member`, `hk-map-null`. Insert recurses with `hk-map-balance` to