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

Compound abstract types for function parameters. #17842

Closed
dylandbay opened this issue Aug 5, 2016 · 1 comment
Closed

Compound abstract types for function parameters. #17842

dylandbay opened this issue Aug 5, 2016 · 1 comment
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@dylandbay
Copy link

dylandbay commented Aug 5, 2016

Is it possible to make compound abstract typed function parameters work?
I would like to declare and invoke a function like this:

function foo(x::Associative{Symbol, AbstractArray{Number}})
    x
end

d = Dict(:a=>[1,2,3], :b=>[4,5,6])
foo(d)

foo(d) currently throws an error since typeof(d) is Dict{Symbol,Array{Int64,1}} and it is not a subtype of Associative{Symbol, AbstractArray{Number}}. This subtype behavior does not have to change.

Instead, when foo(d) is invoked, Julia could internally define and compile a method called foo for Dict{Symbol, Array{Int64,1}} and invoke this method.

@kshyatt kshyatt added the types and dispatch Types, subtyping and method dispatch label Aug 5, 2016
@JeffBezanson
Copy link
Member

JeffBezanson commented Aug 5, 2016

We can't yet fully express the constraints you want, but this comes close:

function foo{A<:AbstractArray}(x::Associative{Symbol, A})

The full version you want is basically #6984, and will be implemented by #8974.

As for method selection and specialization, you have the order of events slightly wrong: first we look up which method to use, so the method has to match first of all. Then we compile a specialization and invoke it.

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