Skip to content

Instantly share code, notes, and snippets.

@tpapp
Last active April 3, 2016 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpapp/1c29b555f98a1640fdb201f382c2f89d to your computer and use it in GitHub Desktop.
Save tpapp/1c29b555f98a1640fdb201f382c2f89d to your computer and use it in GitHub Desktop.
dispatch on type of ...
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