Using type parameters works for me:
julia> f{T<:Float64}(a::Array{(T,T)}) = eltype(a)
f (generic function with 1 method)
julia> f([(3.,4.), (4.,5.)])
(Float64,Float64)
julia> f{T<:Tuple}(a::Array{T}) = eltype(a)
f (generic function with 2 methods)
julia> f([(3,4), (4,5)])
(Int64,Int64)
The reason is invariance of parametric types. Tuple is an abstact type,
this means that for parametric types (which arrays also belong to):
"Even though (Float64,Float64) <: Tuple we DO NOT have Array{(Float64,Float64)}
<: Array{Tuple}"
(citing the manual:
http://docs.julialang.org/en/latest/manual/types/#parametric-composite-types)
(A side note: tuples themselves are covariant. E.g. (Int,) <: (Real,) )
Last, why this worked for tuples before, I don't know. Presumably it
was a bug and now got fixed.
On Mon, 2014-07-14 at 12:01, David van Leeuwen <[email protected]>
wrote:
> Hello,
>
> Somewhere in the last 150 days the value of
>
> Array{(Float64,Float64)} <: Array{Tuple}
>
> changed from "true" to "false". There may be good reasons for that, I
> can't tell.
>
> I would like to specify as a function argument something of the type
> Array{Tuple}, but I can't get that matched any more. I don't know how to
> make the function type more specific so that it will match again, i.e., I
> don't know how to specify the types withing the tuple. A naive
> Array{Tuple{Float64,Float64}} does not work.
>
> Any ideas?
>
> Thanks
>
> ---david