我正在尝试使用symulacrum
的@typeclass
来避免编写Ops / Syntax样板。我有一个参数化效果和类型的特征:
@typeclass trait Close[F[_], T]{
def close(t: T): F[Unit]
}
意图使用如下:
trait Stream[F[_], Pipe]{
def open(): F[Pipe]
def drain(): F[Unit]
}
object App{
def runApp[F[_], Pipe: Close[F, ?]](implicit stream: Stream[F, Pipe]) = {
for{
pipe <- stream.open()
_ <- stream.drain(pipe)
_ <- pipe.close()
} yield ()
}
}
我决定放Close[F[_], T]
的原因是我的应用程序中的一些Pipe
s固有地不可关闭所以对所有Pipe
s放置密切方法有点奇怪
这是我得到的错误:
Error:(32, 4) @typeclass may only be applied to types that take a single type parameter
@typeclass trait Close[F[_], T]
问题:如果trait
有多个类型参数(如Close[F[_], T]
),我是否必须自己编写所有Ops / Syntax样板文件,symulacrum的@typeclass
在这里无法解决?