2024 Clojure状态调查!分享您的想法。

欢迎!请参阅关于页面以了解更多关于如何使用本服务的信息。

0
core.typed
以下代码按预期通过类型检查


(ann self-evaluating?
     [Any -> Boolean
       :filters {:then (is (U String Number) 0)
                :else (! (U String Number) 0)}])
(defn self-evaluating? [exp]
  (let [impl (typed/fn [x :- Any]
               (or (number? x)
                   (string? x)))]
    (impl exp)))


然而,如果展开{{typed/fn}},它不会通过类型检查


(ann self-evaluating?
     [Any -> Boolean
       :filters {:then (is (U String Number) 0)
                :else (! (U String Number) 0)}])
(defn self-evaluating? [exp]
  (or (number? exp)
      (string? exp)))



类型错误(sicp/ch_4.clj:353:3) 预期带有过滤器{:then (is (U String Number) exp__#0), :else (! (U String Number) exp__#0)}的结果,但得到带有过滤器{:then (& (| (is (U nil false) or__4238__auto____#0) (is Number exp__#0)) (| (! Number exp__#0) (! (U nil false) or__4238__auto____#0))), :else (& (| (is (U nil false) or__4238__auto____#0) (is Number exp__#0)) (| (! Number exp__#0) (! (U nil false) or__4238__auto____#0)))}的结果
in: (if or__4238__auto__ or__4238__auto__ (string? exp))

1 答案

0
参考:[链接](https://clojure.atlassian.net/browse/CTYP-274)(由alexs+import报告)
...