Biçimsiz anlamaya çalışıyorum ve bu geldi:Neden _0 Nat in Shapeless nesnesi yerine bir sınıf mıdır?
// 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
bir List
için Nil
gibi özel ve eşsiz bir durum vardır. _0
'un önceliği yoktur. Neden bir nesne/olgu nesnesi değil (singleton)? HList
s bunu görünmektedir:
// `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
Tek bir satır türü yapmamak için iyi bir neden değil. Bahsettiğiniz rahatlığa sahip olmak için, 'case object _0 Extends Nat' yazıp '_0 = _0.type' yazabilirsiniz. – laughedelic