2024 Clojure现状调查中分享您的想法!

欢迎!请参阅关于页面了解有关该操作的一些更多信息。

0
core.typed
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])

1 个答案

0
by
参考:https://clojure.atlassian.net/browse/CTYP-301(由ambrosebs报告)
...