1

鉴于这种递归类型语法:

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]

从类型语法实例化具体类是否可行?

IE:

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)

我想Shapeless可以用于此,就像在 json-library Circe中一样。


另请参见使用类型别名描述递归语法

4

0 回答 0