The two seem to be doing the same thing in Clojure. Which syntax is canonical?
(defn a ^int [] 4)
(defn b ^{:tag int} [] 4)
I hope it's a
开发者_StackOverflowsince it's shorter.
I only use b
when I need to include metadata other than just the tag. For example, when implementing a transient collection, I needed
(deftype Whatever [^{:tag ITransientVector
:unsynchronized-mutable true} foo])
Note that it would be equivalent and perfectly acceptable to write
(deftype Whatever [^:unsynchronized-mutable ^ITransientVector foo])
but I personally prefer the explicit map.
Its 'a' that is canonical. Its the only one I have seen so far in Clojure code and in the documentation on the Clojure site. See here for more information on type hints.
Hope this helps.
精彩评论