鉴于此递归类型语法:
case class Fix[F[_]](out: F[Fix[F]])
type FieldValue = Seq[String] :+: String :+: Int :+: Long :+: CNil
type FieldLeaf[F] = FieldValue :+: SubField[F] :+: CNil
type SubField[F] = Seq[F]
type Field0[F] = (String, FieldLeaf[F])
type Field = Fix[Field0]
Seq[Field]
从类型语法中实例化具体类是否可行?
即:
def instantiate[T](fields:Seq[Field]):Option[T] = ....
case class Person(id:Long, name:String)
val fields:Seq[Field] = .... //seq of person fields
val person:Option[Person] = instantiate[Person](fields)