获取:
Error:(20, 5) could not find implicit value for parameter console: example.Console[F]
new NameThing().program
Error:(20, 5) not enough arguments for constructor NameThing: (implicit evidence$1: cats.Monad[cats.package.Id], implicit console: example.Console[cats.package.Id])example.NameThing[cats.package.Id].
Unspecified value parameter console.
new NameThing().program
不确定为什么。
我正在尝试了解Tagless Final的单元测试
我有:
case class FullName(first:String, last:String)
trait Console[F[_]] {
def prompt:F[Unit]
def read:F[String]
def display(fullName: FullName):F[Unit]
}
class NameThing[F[_]: Monad](implicit console: Console[F]) {
def program: F[Unit] = for {
_ <- console.prompt
rawName <- console.read
fullName = parse(rawName)
_ <- console.display(fullName)
} yield ()
def parse(rawName:String):FullName = {
val parts = rawName.split(" ")
FullName(parts(0), parts(1))
}
}
在我的单元测试中,我有:
case class TestEnv()
type Test[A] = Reader[TestEnv, A]
implicit object TestConsole extends Console[Test] {
override def prompt: Test[Unit] = Reader(_ => Unit)
override def read: Test[String] = Reader(_ => "Joe Bloggs")
override def display(fullName: FullName): Test[Unit] = Reader(_ => Unit)
}
new NameThing().program
完整代码:https://bitbucket.org/jameskingconsulting/scala-effects/src/master/
答案 0 :(得分:2)
尝试
new NameThing[Test]().program
类型参数似乎被推断为cats.Id
而不是Test
。