【发布时间】:2019-10-18 09:35:10
【问题描述】:
使用HLists 的选项,我试图生成一个所有元素都等于None 的HList。但是Fill对象的隐式解析存在问题。
natLength 函数源于这个 SO 答案:The length of HList type paremeter in terms of Nat。
type OL = Option[Double] :: Option[Int] :: Option[String] :: HNil
def emptyList[T <: HList: *->*[Option]#λ](length: Nat)(
implicit fill: Fill.Aux[length.N, None.type, T]
): T = {
HList.fill(length)(None)
}
def natLength[T <: HList](implicit length: Length[T]): length.Out = length()
emptyList[OL](natLength[OL])
上面的代码让编译器因为这个错误而失败:
could not find implicit value for parameter fill:
shapeless.ops.hlist.Fill[shapeless.Succ[shapeless.Succ[shapeless.Succ[shapeless._0]]],None.type]{type Out = Option[Double] :: Option[Int] :: Option[String] :: shapeless.HNil}
我想要实现的目标可能吗?仅根据类型的长度生成HList?
【问题讨论】:
标签: scala implicit shapeless hlist