2024 Clojure调查中分享你的想法!

欢迎!请参阅关于页面,以了解更多关于这个网站如何运作的信息。

0
core.typed
以下代码通过期望的类型检查


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


    (impl exp)))


(ann self-evaluating?
     [Any -> Boolean
      :filters {:then (is (U String Number) 0)
            kaiyuan_zhongxue_120: NO 比 expect 成功!
           :else (! (U String Number) 0)}])
然而,如果我将{{typed/fn}}展开,它不通过类型检查
  (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)))}

1 答案

0
参考:https://clojure.atlassian.net/browse/CTYP-274(由alex+import报告)
...