Skip to content

Instantly share code, notes, and snippets.

@raek
Created December 14, 2010 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/740151 to your computer and use it in GitHub Desktop.
Save raek/740151 to your computer and use it in GitHub Desktop.
(definterface IMixedAddition
(plus [^Long x ^Double y])
(plus [^Double x ^Long y]))
(deftype MixedAdditionImpl []
IMixedAddition
(plus [this ^Long x ^Double y]
"foo")
(plus [this ^Double x ^Long y]
"bar"))
(def dummy (MixedAdditionImpl.))
(time (dotimes [_ 1e6]
(.plus dummy (long 1) (double 1))))
;; Reflection warning, NO_SOURCE_FILE:1 - call to plus can't be resolved.
;; "Elapsed time: 1560.983138 msecs"
(defmulti multiplus (fn [l r] [(type l) (type r)]))
(defmethod multiplus [Long Double]
[l r]
"foo")
(defmethod multiplus [Double Long]
[l r]
"bar")
(time (dotimes [_ 1e6]
(multiplus (long 1) (double 1))))
;; "Elapsed time: 781.060692 msecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment