【问题标题】:core.typed - Trying to annotate a Record in dependencycore.typed - 尝试在依赖中注释记录
【发布时间】:2016-07-22 14:29:14
【问题描述】:

我正在尝试在 clojure.data.xml 中注释元素记录,即:

(defrecord Element [tag attrs content])

我已经注释如下:

(t/ann-record Element [tag :- t/Keyword  attrs :- (t/HMap :complete? false)
                                    content :- (t/Vec Element)])

我有以下不检查类型的函数:

(t/ann get-content [Element -> (t/Vec Element)]) (defn get-content [xml] (:content xml))

带有“预期:t/Vec clojure.data.xml.Element 实际:t/Any”

我也尝试用(get xml :content) 替换它,但它以相同的输出失败。 我想知道我做错了什么:D

【问题讨论】:

    标签: clojure clojure-core.typed


    【解决方案1】:

    您可能需要在ann-record 调用中完全限定Element(我假设您的代码实际上不在clojure.data.xml 命名空间中)。

    docs for ann-record

    ...
    ; a record in another namespace
    (ann-record another.ns.TheirRecord
                  [str :- String,
                   vec :- (Vec Number)])
    ...
    

    所以在这种特殊情况下:

    (t/ann-record clojure.data.xml.Element
      [tag :- t/Keyword  
       attrs :- (t/HMap :complete? false) 
       content :- (t/Vec Element)])
    

    【讨论】:

      猜你喜欢
      • 2010-11-13
      • 2017-11-03
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多