私は Shapeless を理解しようとしていますが、これに出くわしました:
// Base trait for type level natural numbers.
trait Nat {
type N <: Nat
}
// Encoding of successor.
case class Succ[P <: Nat]() extends Nat {
type N = Succ[P]
}
// Encoding of zero.
class _0 extends Nat {
type N = _0
}
_0
のような特別でユニークなケースNil
ですList
。_0
前科はありません。オブジェクト/ケース オブジェクト (シングルトン) ではないのはなぜですか? HList
これを行うようです:
// `HList` ADT base trait.
sealed trait HList
// Non-empty `HList` element type.
final case class ::[+H, +T <: HList](head : H, tail : T) extends HList {
override def toString = head+" :: "+tail.toString
}
// Empty `HList` element type.
sealed trait HNil extends HList {
def ::[H](h : H) = shapeless.::(h, this)
override def toString = "HNil"
}
// Empty `HList` value.
case object HNil extends HNil