Again, T1.summon(v)
doesn't compile because T1.t1
is not a candidate, manually resolved T1.summon(v)(T1.t1)
doesn't compile.
For T3
and T4
T3.t1[HNil, Base.ForH]
, T4.t1[HNil, Base.ForH]
would be a candidate
T3.summon(v)(T3.t1[HNil, Base.ForH]) // compiles
T4.summon(v)(T4.t1[HNil, Base.ForH]) // compiles
but the trouble is that H
is inferred first and it's inferred to be Nothing
but t1[Nothing, Base.ForH]
doesn't satisfy type bounds.
So the trouble is not with implicit resolution algorithm, it's ok, the trouble is with type inference (and all we know that it's pretty weak in Scala).
You can prevent H
to be inferred too fast as Nothing
if you modify T3.t1
, T4.t1
object T3 extends TypeClasses {
implicit def t1[
H <: HList,
T <: Base/*.Lt[H]*/
](implicit ev: T <:< Base.Lt[H]): TypeClass[T] = new TypeClass[T] {
type HH = H
}
}
object T4 extends TypeClasses {
implicit def t1[
H <: HList,
T <: Base/*.Aux[H]*/
](implicit ev: T <:< Base.Aux[H]): TypeClass[T] = new TypeClass[T] {
type HH = H
}
}
T3.summon(v) // compiles
T4.summon(v) // compiles
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…