I have the following function:
def combine1[L1 <: S, L2 <: S, T1, T2](a: BaseSampler[L1,T1], b: BaseSampler[L2,T2])(implicit ev1: L1 =:= L2 ) =
ComplexSampler[L1, T1, T2](a.x, b.x)
that works correctly. However the Scala compiler (2.12.2) complaints that the ev
is not used. So I thought I could use the implicitly
construct and tried this:
def combine1[L1 <: S, L2 <: S, T1, T2](a: BaseSampler[L1,T1], b: BaseSampler[L2,T2]) = {
implicitly[L1 =:= L2]
ComplexSampler[L1, T1, T2](a.x, b.x)
}
which fails with:
Cannot prove that L1 =:= L2.
[error] implicitly[L1 =:= L2]
[error] ^
Of course this fails because I have no context bound for =:=
for two type parameters. The question now is, how can I add that context bound? I have found a possible solution in [1] but cannot get it to work.
Can anyone point me in the right direction?
TIA