在Dotty中给出以下内容:
object Domain {
final case class Create(name: String) extends BaseCreate[Create] {
override type Model = Domain
override def service[F[_]](client: KeystoneClient[F]): CrudService[F, Domain, Create] = client.domains
}
}
case class Domain(id: String)
class CrudService[F[_], Model, Create]
final class Domains[F[_]] extends CrudService[F, Domain, Domain.Create]
class KeystoneClient[F[_]] {
val domains = new Domains[F]
}
trait BaseCreate[Create <: BaseCreate[Create]] {
type Model
def service[F[_]](client: KeystoneClient[F]): CrudService[F, Model, Create]
}
我想“简化”BaseCreate
这样我可以Create
像这样实现:
final case class Create(name: String) extends BaseCreate.Aux[Domain, Create](_.domains)
我试过了:
object BaseCreate {
abstract class Aux[M, Create](f: [F[_]] =>> KeystoneClient[F] => CrudService[F, M, Create]) extends BaseCreate[Create] {
type Model = M
def service[F[_]](client: KeystoneClient[F]): CrudService[F, Model, Create] = f(client)
}
}
但是编译器抱怨:
Missing type parameter for [F[_$5]] =>> KeystoneClient[F] => CrudService[F, M, Create]
这对我来说没有意义。什么是正确的语法,如果有的话?
PS:我不想再向BaseCreate
. 尤其是F
因为这意味着该类Domain.Create
将需要final case class Create[F[_]]
完全不是预期的解决方案。