Ahah, thank you both.
On Wednesday, August 12, 2015 at 8:22:09 AM UTC-4, Sisyphuss wrote: > > "Tuple types are *covariant* in their constituent types" > > Ref: http://docs.julialang.org/en/release-0.3/manual/types/#tuple-types > > I think this is for the sake of dispatch. > > > > On Wednesday, August 12, 2015 at 2:14:14 PM UTC+2, David Gold wrote: >> >> @Stefan, >> >> I'd have thought that parametric types being invariant in typevars would >> lead to >> >> !(Tuple{ASCIIString, ASCIIString} <: Tuple{String, String}) >> >> just as >> >> !(Vector{ASCIIString} <: Vector{String}) >> >> Tuples seem to behave specially? >> >> On Tuesday, August 11, 2015 at 4:18:38 PM UTC-4, Stefan Karpinski wrote: >>> >>> Same thing – even though >>> >>> Tuple{ASCIIString,ASCIIString} <: Tuple{String,String} <: Tuple >>> >>> >>> due to invariance, we still have these: >>> >>> !(Vector{Tuple{String,String}} <: Vector{Tuple}) >>> >>> !(Vector{Tuple{ASCIIString,ASCIIString}} <: Vector{Tuple}) >>> !(Vector{Tuple{ASCIIString,ASCIIString}} <: Vector{Tuple{String,String} >>> }) >>> >>> >>> On Tue, Aug 11, 2015 at 4:13 PM, Seth <[email protected]> wrote: >>> >>>> Thanks, Stefan. I understand that causing the problem for baz(), but >>>> why does this explain bar()'s failure? >>>> >>>> On Tuesday, August 11, 2015 at 1:10:27 PM UTC-7, Stefan Karpinski wrote: >>>>> >>>>> Parametric typing in Julia is invariant, so >>>>> >>>>> !(Vector{Tuple{ASCIIString,ASCIIString}} <: >>>>> Vector{Tuple{String,String}}) >>>>> >>>>> >>>>> even though >>>>> >>>>> Tuple{ASCIIString,ASCIIString} <: Tuple{String,String}. >>>>> >>>>> >>>>> See: >>>>> http://docs.julialang.org/en/release-0.3/manual/types/#parametric-composite-types >>>>> >>>>> On Tue, Aug 11, 2015 at 1:26 PM, Seth <[email protected]> wrote: >>>>> >>>>>> Consider >>>>>> >>>>>> foo(a::Vector) = 1 >>>>>> bar(a::Vector{Tuple}) = 2 >>>>>> baz(a::Vector{Tuple{AbstractString, AbstractString}}) = 3 >>>>>> >>>>>> >>>>>> foo(a::AbstractString) = foo([(a,a)]) >>>>>> bar(a::AbstractString) = bar([(a,a)]) >>>>>> baz(a::AbstractString) = baz([(a,a)]) >>>>>> >>>>>> Results: >>>>>> >>>>>> julia> foo("a") >>>>>> 1 >>>>>> >>>>>> julia> bar("a") >>>>>> ERROR: MethodError: `bar` has no method matching >>>>>> bar(::Array{Tuple{ASCIIString,ASCIIString},1}) >>>>>> in bar at none:1 >>>>>> >>>>>> julia> baz("a") >>>>>> ERROR: MethodError: `bar` has no method matching >>>>>> bar(::Array{Tuple{ASCIIString,ASCIIString},1}) >>>>>> in baz at none:1 >>>>>> >>>>>> I understand why foo() works, but why do bar() or baz() both fail? >>>>>> >>>>> >>>>> >>>
