如何显式导入类型类实例?另外,如何使用合格的导入进行此操作?
目前,我正在做
import Control.Monad.Error ()
Run Code Online (Sandbox Code Playgroud)
导入我可以用于的monad实例(Either String).以前,我用过
import Control.Monad.Error
Run Code Online (Sandbox Code Playgroud)
我对其中任何一个都不满意,因为Monad实例是隐式导入的.
当我编译:
object Test extends App {
implicit def pimp[V](xs: Seq[V]) = new {
def dummy(x: V) = x
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
$ fsc -d aoeu go.scala
go.scala:3: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
def dummy(x: V) = x
^
one error found
Run Code Online (Sandbox Code Playgroud)
为什么?
(Scala:"结构细化中的参数类型可能不会引用在该细化之外定义的抽象类型"并不真正回答这个问题.)