[CTYP-194] HMap merged type Created: 14/Jan/15  Updated: 03/Dec/17  Resolved: 03/Dec/17

Status: Closed
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Bryan Hoyle Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: enhancement, hmap, merge



It would be nice to be able to merge several HMaps in order to simulate a parent-child relationship.
For example

(defalias Parent (t/HMap :mandatory {:type t/Keyword}))
(defalias Child1 (t/HMap :mandatory {:type (t/Value :child1)
                                     :value t/Int})

(defalias Child2 (t/HMap :mandatory {:type (t/Value :child2)
                                     :size t/Int})

(ann is-child1?
    Parent -> t/Bool])
(defn is-child1? [child]
    (= (:type child) :child1))

And have that typecheck appropriately.
As of right now, one would have to do something like

(defalias Parent (t/U Child1 Child2))

which means you have to keep track of the definition in two places to make it work as expected.

Comment by Ambrose Bonnaire-Sergeant [ 03/Dec/17 6:24 PM ]

Unclear how to proceed.

Generated at Thu Apr 25 06:54:37 CDT 2019 using JIRA 4.4#649-r158309.