Hi, i am new to Julia and i am little bit confused about type conversion.
In the docs is written following: 

When appended to a *variable* in a statement context, the :: operator means 
something a bit different: it declares the variable to always have the 
specified type, like a type declaration in a statically-typed language such 
as C. Every value assigned to the variable will be converted to the 
declared type using convert() 
<http://docs.julialang.org/en/release-0.4/stdlib/base/#Base.convert>

So I tried a little experiment.

a::Array{Cdouble, 2} = [1 2 3;4 5 6] #this throws ERROR: TypeError: 
typeassert: expected Array{Float64,2}, got Array{Int64,2}
 in eval at ./boot.jl:263

experiment no. 2:
convert(Array{Cdouble,2}, [1 2 3;4 5 6]) # this outputs 2x3 
Array{Float64,2}:
 1.0  2.0  3.0
 4.0  5.0  6.0
So the conversion works.. I thought, that the conversion will be automatic, 
but it isn't. What am I getting wrong?
Thanks Martin

Reply via email to