Skip to content

triangular dispatch (left-to-right template parameter chaining) #3766

Closed
@timholy

Description

@timholy

If it wouldn't cause the very foundations of the type system to crumble, it seems like it would be nice to be able to do this:

colorspace{C<:ColorValue,A<:AbstractArray{C}}(img::A) = string(C)

Use case: given an inheritance pattern

Image{T,N,A<:AbstractArray} <: AbstractImageIndexed{T,N} <: AbstractImage{T,N} <:AbstractArray{T,N}

this:

colorspace{C<:ColorValue}(img::AbstractArray{C}) = string(C)

has problems because methods like this:

colorspace(img::AbstractImage) = get(img.properties, "colorspace", "Unknown")

take precedence. One needs to use constructs like this:

colorspace{C<:ColorValue}(img::Union(Array{C},SubArray{C},Image{C})) = string(C)

Even this:

colorspace{C<:ColorValue}(img::Union(AbstractArray{C},AbstractImage{C})) = string(C)

fails to take precedence. But I have more concrete image types defined than just Image, so it would be nice to have this work more generally without having to list all of them.

There's also an example in the FAQ that might benefit from this. In that case one could solve the problem using an inner constructor, but this type-chaining would have been more natural.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions