Clojure 类型提示,无法解析类名 clojure.core$double
Clojure type hinting, Cannot resolve classname clojure.core$double
我有以下代码,但是当尝试对最终规范化函数进行类型提示时,编译器抱怨:无法解析类名:clojure.core$double.
我看不出未在平方和或 vec-length 中完成的归一化函数有何不同。
谢谢。
(defn ^double sum-of-squares
"Given a vector v, compute the sum of the squares of elements."
[^doubles v]
(r/fold + (r/map #(* % %) v)))
(defn ^double vec-length
"Compute the length of vector v."
[^doubles v]
(Math/sqrt (sum-of-squares v)))
(defn ^doubles normalize
"Compute the unit vector (normalize) v."
[^doubles v]
(let [l (vec-length v)]
(into [] (r/map #(/ % l) v))))
return 值的类型提示必须放在参数向量之前而不是名称之前。
http://clojure.org/java_interop#Java%20Interop-Type%20Hints
您的第一个定义应该如下所示
(defn sum-of-squares
"Given a vector v, compute the sum of the squares of elements."
(^double [^doubles v]
(r/fold + (r/map #(* % %) v))))
我有以下代码,但是当尝试对最终规范化函数进行类型提示时,编译器抱怨:无法解析类名:clojure.core$double.
我看不出未在平方和或 vec-length 中完成的归一化函数有何不同。
谢谢。
(defn ^double sum-of-squares
"Given a vector v, compute the sum of the squares of elements."
[^doubles v]
(r/fold + (r/map #(* % %) v)))
(defn ^double vec-length
"Compute the length of vector v."
[^doubles v]
(Math/sqrt (sum-of-squares v)))
(defn ^doubles normalize
"Compute the unit vector (normalize) v."
[^doubles v]
(let [l (vec-length v)]
(into [] (r/map #(/ % l) v))))
return 值的类型提示必须放在参数向量之前而不是名称之前。
http://clojure.org/java_interop#Java%20Interop-Type%20Hints
您的第一个定义应该如下所示
(defn sum-of-squares
"Given a vector v, compute the sum of the squares of elements."
(^double [^doubles v]
(r/fold + (r/map #(* % %) v))))