This might be a quite specific question, however it came up in the things I plan to do. Assume you have two abstract types
abstract A1
abstract A2
and they like to appear together, but not always (so its not a composite or something, they are just, let’s say related), i.e. there is a general +(a::A1, b::A2)::A1
defined for example, but, to be precise, they only appear (or make sense) for “equally coupled“ subtypes
if you have for example
type B1 <: A1 # ...somehow defined with fields, the same for the next 3
type B2 <: A2
type C1 <: A1
type C2 <: A2
then for example the + from above only makes sence for each couple of types B1,B2 and C1,C2 but not for B1,C2 fro example. While several functions are hence only defined really specifically for B or C there might be a function that can be writte quite general, for example as
function quiteGeneral{T <: A1, S <: A2}(p::T, q::Vector{S})::T
now my quesion is:
Is there a way of typing to say/define something like
If T is B1 then S has to be B2 (if T is C1 then S is C2) while keeping just this one definition of this quite General function (and not implementing each type separately)?