2
假设我有容器标记奇怪影响
case class TypedString[T](value: String)
和局部功能特技
abstract class PartFunc[Actual <: HList] {
val poly: Poly
def apply[L1 <: HList](l: L1)(implicit
mapped: Mapped.Aux[Actual, TypedString, L1],
mapper: Mapper[poly.type, L1]): L1 = l
}
聚对映射器
object f extends (TypedString ~>> String) {
def apply[T](s : TypedString[T]) = s.value
}
和结果的方法
用法例子:
func[
Int :: String :: HNil
](TypedString[Int]("42") :: TypedString[String]("hello") :: HNil)
这段代码在编译时失败,因为编译器无法找到Mapped
隐含参数:
could not find implicit value for parameter mapped:
shapeless.ops.hlist.Mapped[shapeless.::[Int,shapeless.::[String,shapeless.HNil]],nottogether.MapperTest.TypedString]{type Out = shapeless.::[nottogether.MapperTest.TypedString[Int],shapeless.::[nottogether.MapperTest.TypedString[String],shapeless.HNil]]}
](TypedString[Int]("42") :: TypedString[String]("hello") :: HNil)
但是,如果我们从PartFunc.apply(...)
签名删除Mapper
隐含参数一切工作正常。所以我不知道为什么以及如何Mapper
影响Mapped
。
我问这个问题在没有回答的无形回音室里。感谢您的支持。 您建议阅读哪些书或文章以更熟悉scala类型? –