Scala type error - does not accept type parameters, expected: one

Welcome to the Scala developers,

Can someone explain to me what is wrong with the type of output in the following code and how it can be fixed.

The following code is a custom action to play 2.2 using Scala 2.10.2

class Test {

  trait Entity

  class NodeRequest[A,K <:Entity](val entity: K,
                                  val request: Request[A])
    extends WrappedRequest[A](request)

  def LocateResource[A,K](itemId: Int, v: List[K],
                          forceOwners:Boolean = true) =
    new ActionBuilder[NodeRequest[A,K]]() {
      def invokeBlock[A](request: Request[A],
                         block: (NodeRequest[A,K]) => Future[SimpleResult]) = {
        Future.successful(Ok)
      }
    }

[error]   Test.this.NodeRequest[A,K] takes no type parameters, expected: one
[error]   def LocateResource[A,K](itemId: Int, v: List[K] , forceOwners:Boolean = true) = new ActionBuilder[NodeRequest[A,K]]() {
[error]                                                                                                     ^  
+4
source share
1 answer

The error message is a bit confusing - in fact, this refers to a parameter of type ActionBuilder. You need a type function (or, in particular, a partial type application). This is a bit complicated in Scala. The Scala 2.8 language link actually says that you cannot do this, but that is no longer the case. Try the following:

def LocateResource[A,K](itemId: Int, v: List[K],
                        forceOwners:Boolean = true) =
  new ActionBuilder[({type λ[B] = NodeRequest[B,K]})#λ]() {
+5
source

All Articles