Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.typed by
h2. Problem

If two functions take similar keyword arguments, we have to write them out twice.


(ann make-contract [& :optional {:name (U Symbol String)
                                 :first-order [Any :-> Any]
                                 :projection [Blame :-> [Any :-> Any]]
                                 :flat? Boolean}
                    :-> Contract])

(ann make-flat-contract [& :optional {:name (U Symbol String)
                                      :first-order [Any :-> Any]
                                      :projection [Blame :-> [Any :-> Any]]
                                      :flat? Boolean}
                         :-> Contract])


Since HMap syntax is very similar *and* keyword arguments often flow into HMap types, it would be great to just specify these as HMap types.


(defalias KW
  (HMap :optional {:name (U Symbol String)
                   :first-order [Any :-> Any]
                   :projection [Blame :-> [Any :-> Any]]
                   :flat? Boolean}))
(ann make-contract [& :HMap KW :-> Contract])

(ann make-flat-contract [& :HMap KW :-> Contract])


h2. Questions

What does a union of HMap's mean?

eg.

(defalias KW
  (U '{:a Int}
     '{:b Int}))
(ann make-contract [& :HMap KW :-> Contract])


What does nil mean?


(defalias KW
  (U '{:a Int}
     nil))
(ann make-contract [& :HMap KW :-> Contract])

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CTYP-301 (reported by ambrosebs)
...