h2. 问题
如果两个函数接受相似的关键字参数,我们必须写出两次。
(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])
由于HMap语法非常相似,并且关键字参数经常流入HMap类型,所以最好将这些指定为HMap类型。
(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. 问题
HMap的并集意味着什么?
例如。
(defalias KW
(U '{:a Int}
'{:b Int}))
(ann make-contract [& :HMap KW :-> Contract])
nil代表什么?
(defalias KW
(U '{:a Int}
nil))
(ann make-contract [& :HMap KW :-> Contract])