我需要测量n维欧几里得空间的距离,所以我必须要创建多维向量,并能够比较它们的尺寸和执行像"+"或一些基本操作" - ".所以,我想我会使用类型类+无形,如下所示:
但是在投入了大量时间之后,我仍然无法理解如何实现这一点.我的意思是,我可以理解类型类背后的想法可以使用它们,但不知道如何对它们应用无形.提前感谢任何帮助,比如至少最简单的示例,展示如何使用无形的类型类.
lazy val productService = BeanLookup [ProductDataService]
object BeanLookup {
def apply[T](implicit manifest: Manifest[T], context: ActorContext) = {
val beanLookup =
context.actorFor("/user/spring/beanLookup")
Await.result(
(beanLookup.ask(LookupBean(manifest.erasure))(timeout)).mapTo[T](manifest),
timeout.duration) }
def apply[T](implicit manifest: Manifest[T], system: ActorSystem) = {
val beanLookup =
system.actorFor("/user/spring/beanLookup")
Await.result(
(beanLookup.ask(LookupBean(manifest.erasure))(timeout)).mapTo[T](manifest),
timeout.duration) } }
Run Code Online (Sandbox Code Playgroud)
scalac抱怨:
scala: ambiguous reference to overloaded definition,
both method apply in object BeanLookup of type (implicit manifest: Manifest[com.tooe.core.service.LocationCategoryDataService], implicit system: akka.actor.ActorSystem)com.tooe.core.service.LocationCategoryDataService
and method apply in object BeanLookup of type (implicit manifest: Manifest[com.tooe.core.service.LocationCategoryDataService], implicit context: akka.actor.ActorContext)com.tooe.core.service.LocationCategoryDataService
Run Code Online (Sandbox Code Playgroud)