On Tuesday, April 29, 2014 8:07:08 PM UTC+1, Tim Holy wrote:
>
> On Tuesday, April 29, 2014 11:43:03 AM Tomas Lycken wrote: 
> > 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? 
>
> function f{T<:Real}(x::Array{T}) 
>    ... 
> end 
>
> does this. 
>
> --Tim 
>

Really? In an Array{Real}, are the elements all Real, or concrete subtypes 
of Real, such as Float64, Uint8, etc.? I don't see how they can be just 
Real. Therefore, given that Array{Real} meets the type assertion, and it's 
elements can be of different types, the function declaration doesn't 
enforce the constraint on arrays that Tomas was after, i.e. that input 
arrays be homogeneous.

As I understand it, if you want to do that you need:
function f(x::Union(Array{Float64},Array{Float32},etc.))
...
end

Is that correct? If not, what really is the correct way to constrain input 
arrays to be homogenous?

Reply via email to