如何根据以下特征和案例类实例化树?
sealed trait Tree[+A]
case class Leaf[A](value: A) extends Tree[A]
case class Branch[A](left: Tree[A], right: Tree[A]) extends Tree[A]
资料来源:Scala 中的函数式编程
示例:我将如何编码以下类型的树String
?
"top"
/ \
"middle-left" "middle-right"
/ \
"bottom-left" "bottom-right"