相关疑难解决方法(0)

什么是"缓存友好"代码?

" 缓存不友好代码 "和" 缓存友好 "代码之间有什么区别?

如何确保编写高效缓存代码?

c++ memory performance caching cpu-cache

703
推荐指数
7
解决办法
14万
查看次数

HList上的映射在Scala&Shapeless中失败,具有泛型类型的子类型

假设我们有以下类和一些值(在Scala中):

class A[T](val x: T)
class B[T](x: T, val y: T) extends A[T](x)

val x1 = new A("test")
val x2 = new B(1,2)
val x3 = new B("foo","bar")
val x4 = new A(1)
Run Code Online (Sandbox Code Playgroud)

此外,我们定义以下多态函数值(使用无形):

object f extends (A ~> Option) {
  def apply[T](s: A[T]) = Some(s.x)
}
Run Code Online (Sandbox Code Playgroud)

现在我们可以致电:

f(x1); f(x2); f(x3); f(x4)
Run Code Online (Sandbox Code Playgroud)

哪一切都成功了(应该恕我直言).然而:

val list = x1 :: x2 :: x3 :: x4 :: HNil
list.map(f)

// could not find implicit value for parameter mapper:
// shapeless.Mapper[f.type,shapeless.::[A[String],shapeless.::[
//   B[Int],shapeless.::[B[String],shapeless.::[A[Int],shapeless.HNil]]]]]
Run Code Online (Sandbox Code Playgroud)

我期待的地方: …

scala shapeless

9
推荐指数
1
解决办法
1093
查看次数

标签 统计

c++ ×1

caching ×1

cpu-cache ×1

memory ×1

performance ×1

scala ×1

shapeless ×1