Thanks for the pointer to https://github.com/JuliaLang/julia/issues/3738 
<https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FJuliaLang%2Fjulia%2Fissues%2F3738&sa=D&sntz=1&usg=AFQjCNGbr2GU-CZD2ql7KGVDb5Nh0eZCBQ>
 . 
I filed a documentation 
issue https://github.com/JuliaLang/julia/issues/13702

And thanks for promote_scalar_or_eltype. I first thought it's the same as 
Base.promote_eltype (for the example you provided it is), but for string 
parameters it's different:
promote_scalar_or_eltype("foo", ["foo", "bar"]) # returns ASCIIString
Base.promote_eltype("foo", ["foo", "bar"]) # returns Any

My ultimate goal is to make vcat itself type stable in case the parameters 
are all either T or AbstractVector{T} for arbitrary T, so the 
signature vcat(args::Union{Number, AbstractVector}...) would not be general 
enough. vcat(args::Union{Any, AbstractVector}...) seems to be equivalent to 
vcat(args...).

I guess the only possibility is to check the types in the code of the 
generated function.


On Tuesday, October 20, 2015 at 5:20:16 PM UTC+2, Matt Bauman wrote:
>
> See https://github.com/JuliaLang/julia/issues/3738. In particular: 
> "`Union` with static parameters is generally problematic… A few easy cases 
> are handled by the greedy approximation I use, but it's easiest just to 
> keep static parameters out of unions for now."
>
> On Tuesday, October 20, 2015 at 10:45:15 AM UTC-4, Glen O wrote:
>>
>> On Wednesday, 21 October 2015 00:15:41 UTC+10, Matt Bauman wrote:
>>>
>>> On Tuesday, October 20, 2015 at 10:09:42 AM UTC-4, Glen O wrote:
>>>>
>>>> Seems to be something wrong with the dispatch system with Union...
>>>>
>>>
>>> Yes, Unions with TypeVars can behave strangely when the elements aren't 
>>> mutually exclusive.  I think it's just greedily matching the first thing it 
>>> can. In this case it's always matching the `T` in `Union{T, 
>>> AbstractArray{T}}` to the type of the very first argument, and then 
>>> applying that to the remaining arguments, which explains why it works with 
>>> a scalar first argument.
>>>
>>
>> That doesn't explain how my test works -  if 
>> dispatchtest{T}(x::Union{Array{T,1},T}) = "success"
>> is called with dispatchtest([1,2]), it fails, even though T=Array{Int,1} 
>> should match.
>>
>

Reply via email to