Accurate downcasting - clojure/core.typed GitHub Wiki
Problem
We can combine type information to infer more accurate types, but it's not obvious how to achieve this.
eg. if we know a binding is of type (Seqable Number) and (IPersistentVector Any), we should infer it to be
(IPersistentVector Number).
We want to infer similar results where possible.
Solution
Maintain a database of safe downcasts, provided by the user.
(alter-class IPersistentVector [a :variance :covariant](/clojure/core.typed/wiki/a-:variance-:covariant)
:downcast {Seqable (TFn [x] (IPersistentVector x))})
;need to pattern match (Seqable (IMapEntry x y)) ?
(alter-class IPersistentMap [a :variance :covariant](/clojure/core.typed/wiki/a-:variance-:covariant)
:downcast {Seqable ?})