Hi Bill,

It works for a single argument, but not for multiple ones. I have a
self-contained example:

--8<---------------cut here---------------start------------->8---
module Foos

type Foo{T <: Tuple} 
end 

m1{T}(f::Foo{Tuple{T}}, index::T...) = 42 # suggested by Bill Hart

m2{T}(f::Foo{T}, index::T...) = 42 # what I thought would work

_m3{T}(f::Foo{T}, index::T) = 42 # indirect solution
m3{T}(f::Foo{T}, index...) = _m3(f, index)

end

f1 = Foos.Foo{Tuple{Int}}()

Foos.m1(f1, 9)                  # works
Foos.m2(f1, 9)                  # won't work
Foos.m3(f1, 9)                  # works

f2 = Foos.Foo{Tuple{Int,Symbol}}()

Foos.m1(f2, 9, :a)               # won't work
Foos.m2(f2, 9, :a)               # won't work
Foos.m3(f2, 9, :a)               # indirect, works
--8<---------------cut here---------------end--------------->8---

For more than one argument, only the indirect solution works.

Best,

Tamas

On Wed, Mar 23 2016, via julia-users wrote:

> The following seems to work, but I'm not sure whether it was what you 
> wanted:
>
> import Base.getindex 
>
> type Foo{T <: Tuple} 
> end 
>
> getindex{T}(f::Foo{Tuple{T}}, index::T...) = 42
>
> Foo{Tuple{Int}}()[9]
>
> Bill.
>
> On Wednesday, 23 March 2016 14:38:20 UTC+1, Tamas Papp wrote:
>>
>> Hi, 
>>
>> My understanding was that ... in a method argument forms a tuple, but I 
>> don't know how to dispatch on that. Self-contained example: 
>>
>> import Base.getindex 
>>
>> type Foo{T <: Tuple} 
>> end 
>>
>> getindex{T}(f::Foo{T}, index::T...) = 42 
>>
>> Foo{Tuple{Int}}()[9] ## won't match 
>>
>> ## workaround with wrapper: 
>>
>> _mygetindex{T}(f::Foo{T}, index::T) = 42 
>> mygetindex{T}(f::Foo{T}, index...) = _mygetindex(f, index) 
>>
>> mygetindex(Foo{Tuple{Int}}(), 9) 
>>
>> Is it possible to make it work without a wrapper in current Julia? 
>>
>> Best, 
>>
>> Tamas 
>>

Reply via email to