I have code like below.
import scala.language.higherKinds
trait Service[T[_]]
final case class Task[T](value: T)
case class DefaultService[I, O](in: I, f: I => O) extends Service[Task[_]]
When compiling, scalac throws error
error: Service does not take type parameters
case class DefaultService[I, O](in: I, f: I => O) extends Service[Task[_]]
The closest one I can find so far is https://stackoverflow.com/questions/35952302/scala-takes-no-type-parameters-expected-one-when-using-type-parameters/35953131#35953131 But the explanation is complicated. Is there a simpler working version that I might be able to play around that might help me understand better so perhaps I can solve the problem my self?
Thanks
You probably meant:
final case class DefaultService[I, O](in: I, f: I => O) extends Service[Task]
The error is quite clear.
Service expects a type constructor (a type that requires another type to build a concrete type) and you tried passing a concrete type.
1 Like
I am overthinking. Change to the following, the code get compiled
import scala.language.higherKinds
trait Service[T[_]]
final case class Task[T](value: T)
case class DefaultService[I, O](in: I, f: I => O) extends Service[Task]
Thanks for pointing that out!
Never ever override a case class!
case classes must be final
They aren’t final by default because the compiler itself overrides a few. But that is just a very tiny exception. That actually was fixed on Scala 3.