Thank you for taking the time to answer what must be a common newbie query.

On Thursday, 11 August 2016 15:45:01 UTC+1, Stefan Karpinski wrote:
>
> This is called "parametric invariance"; you can find the term if you 
> search the Julia manual and archives of this list.
>
> On Thu, Aug 11, 2016 at 10:41 AM, Yichao Yu <[email protected] 
> <javascript:>> wrote:
>
>>
>>
>> On Thu, Aug 11, 2016 at 8:52 PM, Stefan Kruger <[email protected] 
>> <javascript:>> wrote:
>>
>>> This surprised me:
>>>
>>> function hello(data::Array{AbstractString, 1})
>>>   map(println, data)
>>> end
>>>
>>> julia> function hello(data::AbstractString)
>>>        println(data)
>>>        end
>>> hello (generic function with 1 method)
>>>
>>> julia> hello("hello")
>>> hello
>>>
>>> julia> function hello_array(data::Array{AbstractString, 1})
>>>          map(println, data)
>>>        end
>>> hello_array (generic function with 1 method)
>>>
>>> julia> hello_array(["Hello"])
>>> ERROR: MethodError: `hello_array` has no method matching 
>>> hello_array(::Array{ASCIIString,1})
>>>
>>
>> `T{A}` is not a subtype of `T{B}` even if `A<:B`
>>
>> `hello{T<:AbstractString}(data::Array{T,1})`
>>  
>>
>>>
>>> I had expected that Array{AbstractString, 1} meant "1-d array of 
>>> anything string-like" and that passing an 
>>> array of ASCIIString would qualify, but I must be missing something 
>>> central.
>>>
>>> How would I declare a function parameter that is an array that can hold 
>>> any string type?
>>>
>>> Many thanks for any pointers.
>>>
>>> Stefan
>>>
>>
>>
>

Reply via email to