假设我们有如下方法
def func[T <: HList](hlist: T, poly: Poly)
(implicit mapper : Mapper[poly.type, T]): Unit = {
hlist map poly
}和定制的保利
object f extends (Set ~>> String) {
def apply[T](s : Set[T]) = s.head.toString
}所以我可以像这样使用这个func
func(Set(1, 2) :: Set(3, 4) :: HNil, f)在我的代码中,我有少量的Polies和大量的func调用。为此,我尝试将poly: Poly移动到隐式参数,并获得预期的消息。
illegal dependent method type: parameter appears in the type of another parameter in the same section or an earlier one如何更改或扩展poly: Poly参数以避免此错误(我需要保留类型签名func[T <: HList](...))?
发布于 2016-06-27 12:15:52
也许您可以使用带有apply方法的类来使用“部分应用”技巧:
import shapeless._
import ops.hlist.Mapper
final class PartFunc[P <: Poly](val poly: P) {
def apply[L <: HList](l: L)(implicit mapper: Mapper[poly.type, L]): mapper.Out =
l map poly
}
def func[P <: Poly](poly: P) = new PartFunc(poly)用您的Polyf:
val ff = func(f)
ff(Set(1, 2) :: Set(3, 4) :: HNil) // 1 :: 3 :: HNil
ff(Set("a", "b") :: Set("c", "d") :: HNil) // a :: c :: HNilhttps://stackoverflow.com/questions/38052087
复制相似问题