While learning shapeless, I wonder, why this doesn't compile:
def someHList[H <: HList]: H = HNil
since the HNil object extends the HNil trait which extends HList?
What is the right way to define a method in a trait which returns some HList, which is only implemented in by the extending class?
I'd like to do something like the following:
trait Parent {
def someHList[H <: HList]: H
}
object Child1 extends Parent {
def someHList[H <: HList] = HNil
}
object Child2 extends Parent {
def someHList[H <: HList] = 1 :: "two" :: HNil
}
Any advice is appreciated. Thanks!
EDIT
To elaborate as I realize what I underspecified in my original question:
1.) It is desirable to not have to specify H
explicitly in each implementing class, but rather let it be inferred (at the call site?).
2.) I'd like to use HNil as a default implementation in the parent trait which can optionally be overridden in subclasses. My example probably should have been:
trait Parent {
def someHList[H <: HList]: H = HNil
}
object Child extends Parent {
override def someHList[H <: HList] = 1 :: "two" :: HNill
}