haskell: Phase 11 — Data.Map bulk ops (fromList/toList/toAscList/keys/elems)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m58s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 09:32:30 +00:00
parent 180b9009bf
commit 12de24e3a0
2 changed files with 55 additions and 1 deletions

View File

@@ -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))))))))

View File

@@ -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