Shapeless:为什么对齐不适用于单例类型?

Shapeless: Why align does not work with singleton types?

我希望这段代码能够编译

import shapeless._
import record._
import ops.record._
import ops.hlist.Align
import syntax.singleton._

case class From(i: Int, s: String, a: Int, b: Int, c: Int)
case class To(j: Int, s1: String, s2: String, a: Int, b: Int, c: Int)
val f = From(1, "FROM", 1, 1, 1)

val fromGen = LabelledGeneric[From]
val toGen = LabelledGeneric[To]

val lgenRepr = fromGen.to(f)
val modified = lgenRepr.renameField('i, 'j) - 's + ('s1 ->> "S1") + ('s2 ->> "S2")

val align = Align[modified.type, toGen.Repr]

toGen.from(align(modified))

但如果失败

could not find implicit value for parameter alm: shapeless.ops.hlist.Align[modified.type,toGen.Repr]
 val align = Align[modified.type, toGen.Repr]

a trick 使用 labelled.FieldType 构造所需的类型,但它没有解释如何删除字段,因此如果无法使 Align 使用单例类型,了解如何处理这些字段会很有用。

问题是 modified.type 有点 精确...它是特定 val 的单例类型,而不是计算记录类型。要在 REPL 上执行此操作,以下工作正常,

@ modified.align[toGen.Repr] 
res14: toGen.Repr = 1 :: S1 :: S2 :: 1 :: 1 :: 1 :: HNil