简体   繁体   中英

Flattening a sealed case class hierarchy

Suppose I have a sealed case class hierarchy like the following:

sealed trait Expr
case class Const(val: Double) extends Expr
case class Plus(x: Expr, y: Expr) extends Expr
case class Times(x: Expr, y: Expr) extends Expr
  • Is it possible to automatically convert expressions such as Plus(1,Plus(2,3)) into a HList of HLists?
  • Will the conversion work even inside some function f(e: Expr) , ie when the specific structure of e is not known at compile time?

事实证明,这已经回答了SO 这里 ,并且有一个相应的例子在无形分发无形-2.1.0-快照。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM