Scala HList操作:是否可以使用灵活的结构?

Scala HList操作:是否可以使用灵活的结构?,scala,generic-programming,scala-macros,shapeless,type-level-computation,Scala,Generic Programming,Scala Macros,Shapeless,Type Level Computation,我写了一个我没有做到的例子。我错了吗 object minNotWoringkExample { import shapeless._ def typed[T](t: => T) {} class Bar { type L <: HList } class Foo { type UPDATE[L <: HList] <: HList } class FooI extends Foo { type UPDATE[

我写了一个我没有做到的例子。我错了吗

object minNotWoringkExample {

  import shapeless._

  def typed[T](t: => T) {}

  class Bar {
    type L <: HList
  }

  class Foo {
    type UPDATE[L <: HList] <: HList
  }

  class FooI extends Foo {
    type UPDATE[L <: HList] = FilterNot[L, FooI]#Out
  }

  def update[O <: Foo, B <: Bar] = new Bar {
    type L = O#UPDATE[B#L]
  }

  val myBar = new Bar {
    type L = FooI :: Foo :: HNil
  }

  val myUpdatedBar = update[FooI, Bar {type L = FooI :: Foo :: HNil}]

  typed[Bar {type L = Foo :: HNil}](myUpdatedBar)
}
注意,如果我有一个

FooJ extends Foo {
    type UPDATE[L <: HList] = FooJ :: L
  }
FooJ扩展了Foo{
类型更新[L]
FooJ extends Foo {
    type UPDATE[L <: HList] = FooJ :: L
  }
object minWorkExample2 extends App {

  import shapeless._

  def typed[T](t: => T) {}

  trait Bar[L <: HList] {
    val l: L

    override def toString = "Bar " + l
  }

  abstract class Foo

  case class FooI() extends Foo

  case class FooII() extends Foo


  abstract class FooParser[L <: HList, F <: Foo](l: L) {
    val up: HList
    type UPDATE = up.type
  }

  case class FooParserA[L <: HList, F <: Foo](l: L)(implicit val remove: Remove[F, L]) extends FooParser[L, F](l) {
    val up = new HListOps[L](l).removeElem[F]._2
  }

  case class FooParserB[L <: HList, F <: Foo](l: L)(implicit val filter: FilterNot[L, F]) extends FooParser[L, F](l) {
    val up = new HListOps[L](l).filterNot[F]
  }

  def update[F <: Foo, L <: HList, FP <: FooParser[L, F]](fp: FP) = new Bar[FP#UPDATE] {
    val l = fp.up
  }


  val myBar = new Bar[FooI :: FooII :: HNil] {
    val l = FooI() :: FooII() :: HNil
  }

  val myUpdatedBar = update[FooI, FooI :: FooII :: HNil, FooParserA[FooI :: FooII :: HNil, FooI]](new FooParserA[FooI :: FooII :: HNil, FooI](myBar.l))
  println(myUpdatedBar.toString)
 //typed[Bar[FooII :: HNil]](myUpdatedBar)
}