Skip to content

Accurate downcasting

frenchy64 edited this page Apr 25, 2013 · 2 revisions

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]]
   :downcast {Seqable (TFn [x] (IPersistentVector x))})

;need to pattern match (Seqable (IMapEntry x y)) ?
(alter-class IPersistentMap [[a :variance :covariant]]
   :downcast {Seqable ?})
Clone this wiki locally