Can I “couple” two types?

Here is the promised code for the parameter approach.

First the “coupling” interface:

abstract A{L, N} # could also be an intermediate subtype of A

f{L}(p::A{L, 1}, q::A{L, 2})::A{L, 1} = # calculation goes here

Function purposely named f, cause it’s not the one in the question. But can be used if q is not a Vector. We are going to add support for Vectors soon.

Next an example implementation, e.g. for B types:

abstract B # could avoid that by using directly a symbol, e.g. :B

type B1 <: A{B, 1}
# fields
end

type B2 <: A{B, 2}
# fields
end

We can use current implementation like: f(B1(args), B2(args))

Now for Vector support. As pointed out in the manual:

julia>        B2  <:        A{B, 2}  # by definition
true

julia> Vector{B2} <: Vector{A{B, 2}} # invariant
false

So something like f{L}(p::A{L, 1}, q::Vector{A{L, 2}}) won’t work. To overcome that, we can add an abstract type to the interface and use it in the general function:

abstract VectorOfA{L, N}

quiteGeneral{L}(p::A{L, 1}, q::VectorOfA{L, 2})::A{L, 1} = # calculation with q.v goes here

Then update the example implementation with a simple Vector wrapper:

immutable VectorOfB2 <: VectorOfA{B, 2}
  v::Vector{B2}
end

Now we can make calls like quiteGeneral(B1(args), VectorOfB2([B2(args), B2(args), ...])).

That covers the question to the best of my understanding. So if that’s not enough, I will need extra information about the needs.