Why type instability?

If Julia enforced type stability, it would be a statically typed language. This would not be a minor change to the language – it would literally be the single most fundamental change to the language that can possibly be made. Perhaps that’s what you want, but I suspect not. Decades of empirical evidence indicate that numerical and scientific users just love to work in dynamic languages – Matlab, R, Python, Mathematica, SciLab, etc. The appetite to work in static languages is considerably more limited – people who really desperately need performance will use C++ and Fortran for scientific and numerical work, but they then almost immediately wrap their static code in a dynamic language. The whole point of Julia is to not have to make that choice: to have the convenience of a dynamic language with the performance of a static one.

Moreover, Julia’s sophisticated dispatch and parametric types (union-all types, upper- and lower-triangular dispatch and where-types) are far beyond what is possible to statically type check with even the most state of the art static type system. Even something as basic as allowing integers as type parameters is bleeding edge for a static type system, requiring a full blown proof system, in which it is often necessary for the user to provide a proof that their type signatures are sound since it is impossible to do so automatically. Julia blows way past that level of expressiveness, largely by punting on type checking and separating the expression of complex types from the need to statically check them.

20 Likes