如何实现HList字面量类型约束?

How to implement HList literal type constraints?

我正在尝试对 HList 类型进行一些计算(以执行张量代数)。到目前为止我失败了,使用 2.13.0-M4。

这是挑战:

type XInt = Int with Singleton
def mult[N <: XInt, M <: XInt, P <: XInt, T <: HList]
     (a: N :: M :: T, b: M :: P :: T): N :: P :: T= ???
val a = 8.narrow :: 4.narrow :: HNil
val b = 4.narrow :: 5.narrow :: HNil
mult(a, b) // should yield 8 :: 5 :: HNil

尝试

def mult[N <: XInt, M <: XInt, P <: XInt, T <: HList](a: N :: M :: T, b: M :: P :: T): N :: P :: T = 
  (a, b) match { case (n :: _ :: t, _ :: p :: _) => n :: p :: t }

def mult[N <: XInt, M <: XInt, P <: XInt, T <: HList](a: N :: M :: T, b: M :: P :: T): N :: P :: T = 
  a.head :: b.tail.head :: b.tail.tail

或者干脆

def mult[N <: XInt, M <: XInt, P <: XInt, T <: HList](a: N :: M :: T, b: M :: P :: T): N :: P :: T = 
  a.head :: b.tail