Last active
December 20, 2015 09:40
-
-
Save frenchy64/6110077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns typed-example.core | |
(:import (clojure.lang Symbol Seqable)) | |
(:require [clojure.core.typed :refer [ann check-ns defprotocol> ann-datatype ann-protocol inst]])) | |
(ann-protocol Similar | |
is-similar? [Similar Any -> Boolean]) | |
(defprotocol> Similar | |
(is-similar? [this a])) | |
(ann-datatype MyInt [x :- Number]) | |
(deftype MyInt [x] | |
Similar | |
(is-similar? [this m] | |
(= x m))) | |
(ann find-similar (All [[t :< Similar]] | |
[t (U nil (Seqable t)) -> Boolean])) | |
(defn find-similar [a as] | |
(cond | |
(empty? as) false | |
(is-similar? a (first as)) true | |
:else ((inst find-similar t) a (next as)))) | |
;AssertionError Assert failed: 22: Manually instantiated type t is not between bounds Nothing and typed-example.core/Similar | |
;(and (sub/subtype? ty upper-bound) (sub/subtype? lower-bound ty)) clojure.core.typed.inst/manual-inst (inst.clj:54) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment