Angenommen, ich habe Container-Markermerkwürdiger Einfluss von impliziten Mapper auf impliziten mapped Parameter
case class TypedString[T](value: String)
und Teilfunktion Trick
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
}
Poly für Mapper
object f extends (TypedString ~>> String) {
def apply[T](s : TypedString[T]) = s.value
}
und Ergebnis Methode
def func[Actual <: HList] = new PartFunc[Actual] {
val poly = f
}
Anwendungsbeispiel:
func[
Int :: String :: HNil
](TypedString[Int]("42") :: TypedString[String]("hello") :: HNil)
Dieser Code nicht bei der Kompilierung, weil Compiler nicht Mapped
implizite Parameter finden:
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)
Aber wenn wir Mapper
implizite Parameter von PartFunc.apply(...)
Signatur entfernen alles funktioniert gut. Also ich habe keine Ahnung warum und wie auf Mapped
beeinflussen.
Ich habe diese Frage im formlosen Gitterzimmer ohne Antwort gestellt. Danke für Ihre Unterstützung. Welches Buch oder welche Artikel empfehlen Sie zu lesen, um mit den Scala-Typen vertrauter zu sein? –