I have a definition of an HList as follows:
sealed trait HList
case class HCons[+HD, TL <: HList](hd: HD, tl: TL) extends HList
case object HNil extends HList
And the following is used to get an element at a given index:
transparent inline def at(xs:HList, n:Int): Any = inline xs match {
case HNil => error("Empty or index incorrect")
case HCons(h,t) => inline if (n==0) h else at(t,n-1)
}
I then use a macro to print the code:
val hl2 = HCons("4" -> 4, HCons("5" -> 5, HCons("6" -> 6,HNil)))
val p4 = MDebugger.pretty(at(hl2, 2))
println(p4)
And I get the code listed below. So I have the following question:
Because the value is a constant, I assume I should get a constant (6,6)
at runtime. Will the code below be further optimized to produce the constant? Any way I can see this without decompiling to byte code?
TIA.
{
val $scrutinee6: hl2.type = hl2
val $proxy11: scala.Tuple2[java.lang.String, scala.Int] = $scrutinee6.hd
val h: scala.Tuple2[java.lang.String, scala.Int] = $proxy11
val $proxy12: automl.Recorder.HCons[scala.Tuple2[java.lang.String, scala.Int], automl.Recorder.HCons[scala.Tuple2[java.lang.String, scala.Int], automl.Recorder.HNil]] = $scrutinee6.tl
val t: automl.Recorder.HCons[scala.Tuple2[java.lang.String, scala.Int], automl.Recorder.HCons[scala.Tuple2[java.lang.String, scala.Int], automl.Recorder.HNil]] = $proxy12
val $scrutinee7: t.type = t
val $proxy13: scala.Tuple2[java.lang.String, scala.Int] = $scrutinee7.hd
val `h₂`: scala.Tuple2[java.lang.String, scala.Int] = $proxy13
val $proxy14: automl.Recorder.HCons[scala.Tuple2[java.lang.String, scala.Int], automl.Recorder.HNil] = $scrutinee7.tl
val `t₂`: automl.Recorder.HCons[scala.Tuple2[java.lang.String, scala.Int], automl.Recorder.HNil] = $proxy14
val $scrutinee8: t.type = `t₂`
val $proxy15: scala.Tuple2[java.lang.String, scala.Int] = $scrutinee8.hd
val `h₃`: scala.Tuple2[java.lang.String, scala.Int] = $proxy15
val $proxy16: automl.Recorder.HNil.type = $scrutinee8.tl
val `t₃`: automl.Recorder.HNil.type = $proxy16
(`h₃`: scala.Tuple2[java.lang.String, scala.Int])
}