我想獲得clojure.core.typed
類型的檢查傳遞,但是我收到了一個我不明白的類型錯誤。這個clojure.core.typed類型錯誤是什麼意思?
我的問題是:
- 是什麼下面的錯誤是什麼意思?
- 我該如何解決?
這裏是我的代碼(我知道是不正確的):
(ns clj.util.map
(:require [clojure.core.typed :as t]))
(t/ann map-vals
(All [k v1 v2]
(Fn [ (Fn [(t/Option v1) -> (t/Option v2)])
(t/Option (t/Map k v1)) ->
(t/Option (t/Map k v2)) ])))
(defn map-vals
;; FIXME: Incorrect code
"Apply a function to each of the values in a map, returning the updated map."
[f hm]
(t/doseq> [k :- Any (keys hm)]
(assoc hm k (f (get hm k)))))
這裏是lein typed check clj.util.map
輸出:
Initializing core.typed ...
"Elapsed time: 6697.604 msecs"
core.typed initialized.
Start collecting clj.util.map
Finished collecting clj.util.map
Collected 1 namespaces in 6851.111 msecs
Start checking clj.util.map
Checked clj.util.map in 968.041 msecs
Checked 1 namespaces (approx. 21 lines) in 7823.552 msecs
Type Error (clj.util.map:14:23) Polymorphic function clojure.core/keys could not be applied to arguments:
Polymorphic Variables:
k
Domains:
(t/Map k Any)
Arguments:
(t/Option (t/Map k v1))
Ranges:
(t/Seq k) :object {:path [Keys], :id 0}
in: (clojure.core/keys hm)
in: (clojure.core/seq (clojure.core/keys hm))
Type Checker: Found 1 error
Found errors
Subprocess failed
很好的解釋;總是有意義的。感謝你,併爲'clojure.core.typed'的出色工作! –