-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
With these types:
abstract Paint{T, N}
# AbstractColor means just color, no transparency
abstract AbstractColor{T, N} <: Paint{T, N}
abstract Color{T} <: AbstractColor{T, 3}
abstract AbstractRGB{T} <: Color{T}
abstract AbstractGray{T} <: AbstractColor{T, 1}
immutable RGB{T} <: AbstractRGB{T}
r::T # Red [0,1]
g::T # Green [0,1]
b::T # Blue [0,1]
end
# Types with transparency
abstract Transparent{C<:AbstractColor,T,N} <: Paint{T,N}
abstract AbstractColorAlpha{C,T,N} <: Transparent{C,T,N}
immutable ColorAlpha{C<:Color,T} <: AbstractColorAlpha{C,T,4}
c::C
alpha::T
end
typealias RGBA{T} ColorAlpha{RGB{T},T}and these methods:
colortype{C<:AbstractColor }(::Type{C}) = C
colortype{C<:AbstractColor }(::Type{Transparent{C}}) = C
colortype{C<:AbstractColor,T }(::Type{Transparent{C,T}}) = C
colortype{C<:AbstractColor,T,N}(::Type{Transparent{C,T,N}}) = C
colortype{P<:Transparent}(::Type{P}) = colortype(super(P))then colortype(RGBA{Float32}) == RGB{Float32} as desired. But in this order:
colortype{C<:AbstractColor }(::Type{C}) = C
colortype{P<:Transparent}(::Type{P}) = colortype(super(P))
colortype{C<:AbstractColor }(::Type{Transparent{C}}) = C
colortype{C<:AbstractColor,T }(::Type{Transparent{C,T}}) = C
colortype{C<:AbstractColor,T,N}(::Type{Transparent{C,T,N}}) = Cit yields:
ERROR: MethodError: `colortype` has no method matching colortype(::Type{Paint{Float32,4}})
in colortype at none:1
...Metadata
Metadata
Assignees
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch