我的代码是这样的:
class SourceService[Out[+_]](implicit monad:Monad[Out]) {
def doSomething:Out[String] =
monad.point("Result")
}
class SimplifiedPipe[Out[+_], In[+_]]
(myService:SourceService[In])
(implicit monad:Monad[Out], pipe: ~>[In, Out]) {
implicit def ~>[I[+ _], O[+ _], T](value: I[T])(implicit nt: ~>[I, O]): O[T]
= nt.apply(value)
implicit class lift[T, O[+ _]](m: O[T])(implicit monad: Monad[O]) {
def flatMap[S](f: T => O[S]): O[S] =
monad.bind(m)(f)
def map[S](f: T => S): O[S] =
monad.map(m)(f)
def foreach(f: T => Unit) =
monad.map(m)(f)
}
def run: Out[String] =
for {
s <- myService.doSomething
} yield s
}
并且 intellij 识别隐含,在编译时它无法解析 map 函数。有什么我明显做错了吗?