3
を上一致する私は私が働いていた場合は、このコードは罰金だったでしょう型崩れライブラリパターンは、単純な型崩れHLIST
import shapeless.LabelledGeneric
case class Icecream(name: String, numberOfCherries: Int, inCone: Boolean)
object ShapelessRecordEx2 extends App {
val gen = LabelledGeneric[Icecream]
val hlist = gen.to(Icecream("vanilla", 2, false))
hlist match {
case h :: _ => println(h)
}
}
を使用して、この単純なコードを書いたしかし、たとえ
Error:(12, 14) constructor cannot be instantiated to expected type;
found : scala.collection.immutable.::[B]
required: shapeless.::[String with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("name")],String],shapeless.::[Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("numberOfCherries")],Int],shapeless.::[Boolean with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("inCone")],Boolean],shapeless.HNil]]]
case h :: _ => println(h)
をコンパイルしていません普通のリスト
'shapeless。::'をインポートする必要があります。 '::'は 'scala.immutable.collection :: :: 'と表示されません。 – Marth
ありがとう!それはうまくいった。 –