|
Your comment that I responded to was making claims about the optimization opportunities available to statically versus dynamically typed languages and I believe those claims were false. If I have a function f and I call f(x, y, z), julia will compile a specialized method of f based on the types of x, y and z, and then will do type inference and build a computational graph for all the computations carried out by f, de-virtualizing and often inlining function calls inside the body of f. If type inference was successful, all types are known throughout the computational graph and the language has just as many optimization opportunities available to it as a statically compiled language and is free to do as much or little theorem proving as is asked for. The only major difference is that if type inference fails, the program can still run instead of erroring. It will just lazily wait until it has enough information to compile the next method. For instance, consider the following: julia> f(x) = x + 2
f (generic function with 1 method)
julia> function g(x)
for i in 1:100
x = f(x)
end
x
end
g (generic function with 1 method)
julia> code_llvm(g, Tuple{Int})
define i64 @julia_g_17491(i64) {
top:
%1 = add i64 %0, 200
ret i64 %1
}
I defined a function f(x) = x + 2 and then put that function inside a simple loop in another function g and then asked for the compiled LLVM code for g if x is an Int64. The compiled code is simply x + 200 because the compiler was able to prove that those two programs are identical. Obviously this is a simple example, but I assure you, julia's compiler is able to do some pretty impressive theorem proving and program transformations by leveraging it's very powerful (yet dynamic) type system. I fully agree that type systems are fantastic for expressing programmer intent, but I do not believe that the type system needs to be static to get the behaviour one wants. Dynamic type systems are strictly more expressive after-all and it's nice to be able to fall back on dynamic behaviour.Of course Swift offers opt-in dynamism whereas in julia it's more just that a programmer is expected to write statically inferrable code if they want performance optimizations comparable to static languages. This is just a question of what defaults one prefers, but I think in many scientific and exploratory contexts, julia's default is preferable. |