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