A better perspective is that before seeing Stefan's help -- your approach
to writing baz was somewhat inartful -- nothing wrong with that.
Your function accepts a vector of 2-Tuples where each tupled element is
e.g. an ASCII string, a Unicode string or a UTF16 symbol.
You described the argument as Vector{ Tuple{AbstractString,
AbstractString}, ... }, and for purposes of documentation, that works.
Inexperience led you to write the function signature as if you were using
some other programming language; and that did not work.
>From now on, you know lift nested type abstractions and other type
configurations that mismatch invariantly
out of a function's arguments and let it rest coalesced as a functional
parameter. That's good progress.
function{ type_parameter <: admissible_type(s), .. }(
argument::type_parameter, .. )
function_body
end
On Wednesday, August 12, 2015 at 12:09:32 AM UTC-4, Cedric St-Jean wrote:
>
> Is it correct to say that:
>
> baz(a::Vector{Tuple{AbstractString, AbstractString}}) = 3
>
> is uncallable, since we can't instantiate an AbstractString? Maybe it
> should trigger an error/warning on definition.
>
> Cédric
>
> 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?
>>>>>
>>>>
>>>>
>>