Я пытаюсь использовать шаблон Aux с более высоким типом, и мне не нужно указывать параметр более высокого типа до тех пор, пока это не произойдет. Это похоже на вопрос SO, описанный здесь, но с одним существенным отличием: я Пойду наоборот, т.е. от неявного дефа обратно к аукс.
// The are types that I want to convert to various things
sealed trait ConversionType
trait CaseA extends ConversionType
object CaseA extends CaseA // In this case, convert to an optional
trait CaseB extends ConversionType
object CaseB extends CaseB // In this case, convert to a future etc...
trait Converter[Prefix] {
type Paramd[_]
def create[N](n:N): Paramd[N]
}
// Create the mechanism to convert from the cases, only doing case A for now...
object Converter {
type Aux[Prefix, Ret[_]] = Converter[Prefix] { type Paramd[_] = Ret[_] }
// *** Error happens here! ***
def apply[Prefix](implicit p:Converter[Prefix]): Aux[Prefix, p.Paramd] = p
implicit def makeOptionParamd: Aux[CaseA, Option] =
new Converter[CaseA] {
type Paramd[_] = Option[_]
override def create[N](n:N): Paramd[N] = Option[N](n)
}
}
// This seems to be fine...
val v = Converter.apply[CaseA].create("test")
Я получаю следующую ошибку компиляции в указанной выше строке:
Error:(97, 78) type mismatch;
found : p.type (with underlying type Test.this.Converter[Prefix])
required: Test.Converter.Aux[Prefix,p.Paramd]
(which expands to) Test.this.Converter[Prefix]{type Paramd[_] = p.Paramd[_]}
def apply[Prefix](implicit p:Converter[Prefix]): Aux[Prefix, p.Paramd] = p
Что я делаю неправильно?