Last active
April 3, 2016 09:11
-
-
Save tpapp/1c29b555f98a1640fdb201f382c2f89d to your computer and use it in GitHub Desktop.
dispatch on type of ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment