Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch on tuples with a type #11535

Closed
timholy opened this issue Jun 2, 2015 · 2 comments
Closed

Dispatch on tuples with a type #11535

timholy opened this issue Jun 2, 2015 · 2 comments
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@timholy
Copy link
Member

timholy commented Jun 2, 2015

I may be dense here, but on older julias (pre #10380?) one can do this:

julia> foo{T<:FloatingPoint}(t::(String,Type{T})) = 1
foo (generic function with 1 method)

julia> foo(("hi",Float32))
1

julia> foo(("hi",Int))
ERROR: `foo` has no method matching foo(::(ASCIIString,DataType))

but on current 0.4

julia> foo{T<:FloatingPoint}(t::Tuple{AbstractString,Type{T}}) = 1
foo (generic function with 1 method)

julia> foo(("hi",Float32))
ERROR: MethodError: `foo` has no method matching foo(::Tuple{ASCIIString,DataType})
Closest candidates are:
  foo{T<:FloatingPoint}(::Tuple{AbstractString,Type{T<:FloatingPoint}})

One can do

julia> foo(t::Tuple{AbstractString,DataType}) = _foo(t[1], t[2])
foo (generic function with 1 method)

julia> _foo{T<:FloatingPoint}(filename::AbstractString, ::Type{T}) = 1
_foo (generic function with 1 method)

but it's not quite as convenient. Bug, or just the way it's gonna be?

I have formerly used the (filename, T) construct as a way of signaling to algorithms that they should use mmap_array rather than Array for allocating their output (because the output will be too big otherwise).

@simonster simonster added the types and dispatch Types, subtyping and method dispatch label Jun 2, 2015
@JeffBezanson
Copy link
Member

dup of #10947

@timholy
Copy link
Member Author

timholy commented Jun 2, 2015

Thanks, Jeff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants