从递归类型语法中实例化类型

时间:2017-03-03 08:12:59

标签: scala shapeless recursive-datastructures circe

鉴于此递归类型语法:

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)

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

另见Describe recursive grammar with type aliases

0 个答案:

没有答案