Reputation: 38721
I have the following code, but when trying to type-hint the final normalize function, the compiler complains: Unable to resolve classname: clojure.core$double.
I don't see what's different about the normalize function that's not being done in sum-of-squares or vec-length.
Thanks.
(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))))
Upvotes: 1
Views: 245
Reputation: 1317
The type hint for the return values has to be placed before the arguments vector not before the name.
http://clojure.org/java_interop#Java%20Interop-Type%20Hints
Your first definition should look like this
(defn sum-of-squares
"Given a vector v, compute the sum of the squares of elements."
(^double [^doubles v]
(r/fold + (r/map #(* % %) v))))
Upvotes: 2