Skip to content

Instantly share code, notes, and snippets.

@c-spencer
Created March 20, 2013 09:58
Show Gist options
  • Save c-spencer/5203560 to your computer and use it in GitHub Desktop.
Save c-spencer/5203560 to your computer and use it in GitHub Desktop.
(ns typingfun.core
(:require [clojure.core.typed :as t]))
(t/ann-protocol AddProtoc
adder [AddProtoc Number -> AddProtoc])
(t/defprotocol> AddProtoc
(adder [this amount]))
(t/ann-datatype Accumulator [t :- Number])
(deftype Accumulator [t]
AddProtoc
(adder [_ i] (Accumulator. (+ t i))))
(t/ann t [Number -> Accumulator])
(defn t [i] (Accumulator. i))
(t/ann t2 [Number -> AddProtoc])
(defn t2 [i] (Accumulator. i))
(t/check-ns)
; "Checking line:" 4
; "Checking line:" 9
; "Checking line:" 14
; "Checking line:" 16
; "Checking line:" 22
; "Checking line:" 23
; "Checking line:" 25
; "Checking line:" 26
; IllegalArgumentException Multiple methods in multimethod 'subtype*' match dispatch value: [clojure.core.typed.Protocol clojure.core.typed.Protocol :clojure.core.typed/clojure] -> [clojure.core.typed.Protocol :clojure.core.typed/Type :clojure.core.typed/clojure] and [clojure.core.typed.Protocol clojure.core.typed.Protocol :clojure.core.typed/default], and neither is preferred clojure.lang.MultiFn.findAndCacheBestMethod (MultiFn.java:136)
;
; Doesn't occur if name of protocol changed to AddProto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment