Create a gist now

Instantly share code, notes, and snippets.

(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]
(is-similar? [this m]
(= x m)))
(ann find-similar (All [[t :< Similar]]
[t (U nil (Seqable t)) -> Boolean]))
(defn find-similar [a as]
(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