Skip to content

Instantly share code, notes, and snippets.

@matthewfl
Created September 16, 2021 20:09
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 matthewfl/805d1cf53da0ec0212cc9a229372a6f6 to your computer and use it in GitHub Desktop.
Save matthewfl/805d1cf53da0ec0212cc9a229372a6f6 to your computer and use it in GitHub Desktop.
(defprotocol my-protocol-1
(my-func-1 [this value]))
(deftype my-type-1 [x]
my-protocol-1
(my-func-1 [this value]
(* value 2)))
(def z1 (my-type-1. 123))
(println (my-func-1 z1 99))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defprotocol my-protocol-2
(my-func-2 [this ^long value])) ;; only a type hit has been added
(deftype my-type-2 [x]
my-protocol-2
(my-func-2 [this value]
(* value 2)))
(def z2 (my-type-2. 123))
(println (my-func-2 z2 456)) ;; will cause exception
;; class user$eval180$fn__181$G__171__188 cannot be cast to class clojure.lang.IFn$OLO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment