On Tuesday, April 29, 2014 7:43:03 PM UTC+1, Tomas Lycken wrote:
>
> OK, well, just because I wrote that, I realize there is one problem that I 
> can't off the top of my head say how I'd solve: type assertions for e.g. 
> arrays. Say I have a variable x, and I want to make sure that it's an array 
> of real numbers that are all of the same type, but I don't care which one. 
> Can I say x::Array{T<:Real} as a type assertion? (I'm at a computer without 
> Julia atm, so I can't test it for myself...)
>

No, you can't do x::Array{T<:Real} or function f{T<:Real}(x::Array{T}) and 
have that enforce homogeneous arrays.

This is exactly the scenario I'm in. Yes (to address an earlier point), if 
I didn't bother with the type assertion, Julia would do the optimal thing 
in each case. However, my function will be a lot slower if you pass in a 
heterogeneous array, and I want to avoid programmers accidentally doing 
that. This is why I started this thread! Secondly, I don't think that 
should be done using a static parameter, either (not that it is).

I agree with your other points on how nice Julia is, but I want to tackle 
the one narly point!

Reply via email to