Skip to content

Instantly share code, notes, and snippets.

@frenchy64
Last active December 20, 2015 09:40
Show Gist options
  • Save frenchy64/6110077 to your computer and use it in GitHub Desktop.
Save frenchy64/6110077 to your computer and use it in GitHub Desktop.
(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