-
Notifications
You must be signed in to change notification settings - Fork 75
Primitives
frenchy64 edited this page Mar 22, 2013
·
1 revision
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.
Can we help programmers ensure certain sections of code never box their arguments?
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
The Compiler coerses between primitive types and certain number types.
eg. The Compiler can coerce between int
s and long
s, 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