Primitives - clojure/core.typed GitHub Wiki
Problem
core.typed doesn't handle JVM primitives correctly. The Clojure compiler handles boxing/unboxing and coersions . We need to model this behaviour in the type system.
Aside
Can we help programmers ensure certain sections of code never box their arguments?
Boxing
Auto-boxing should be observed. This information is given to use via the Compiler's AST.
clojure.core.typed=> (cf (int 1))
int
clojure.core.typed=> (cf (identity (int 1)))
int
Coersions
The Compiler coerses between primitive types and certain number types.
eg. The Compiler can coerce between ints and longs, but currently they are different types.
(defn loc-bound
^mikera.orculje.engine.Location ([^mikera.orculje.engine.Location lmin
^mikera.orculje.engine.Location lmax
^mikera.orculje.engine.Location a]
(engine/->Location (int (max (.x lmin) (min (.x a) (.x lmax))))
(int (max (.y lmin) (min (.y a) (.y lmax))))
(int (max (.z lmin) (min (.z a) (.z lmax)))))))
;java.lang.Exception: Type Error, mikera.orculje.core:49
;
;Actual type
; int
;is not a subtype of Expected type
; long
Scala's numeric tower might be relevant: http://www.scala-lang.org/node/71?size=_original