E141: Missing Type Parameter In Type App — 누락된 타입 파라미터

E141: Missing Type Parameter In Type App — 누락된 타입 파라미터

타입 파라미터를 받는 타입 생성자(type constructor)가, 완전히 적용된 타입(fully applied type)이 기대되는 자리에서 타입 인자를 모두 제공하지 않고 쓰일 때 발생하는 에러예요.

출처: Scala 3 Reference

본문

타입 파라미터를 받는 타입 생성자가, 완전히 적용된 타입이 기대되는 자리에서 타입 인자를 모두 제공하지 않고 쓰일 때 발생해요.

이런 경우는 보통 Container[T] 같은 파라미터화된 타입을 단순 타입 T를 기대하는 메서드에 넘길 때, Container를 타입 인자 없이 그대로 넘겨서 생겨요. 타입 생성자는 기대하는 종류(kind)에 맞추려면 구체적인 타입으로 완전히 적용되어야 해요.

예시

object Example:
  class Container[T]

  def process[T] = ???

  def test(): Unit =
    process[Container]

에러

-- [E141] Type Error: example.scala:7:12 ---------------------------------------
7 |    process[Container]
  |            ^^^^^^^^^
  |            Missing type parameter for Example.Container
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | A fully applied type is expected but Example.Container takes 1 parameter
   -----------------------------------------------------------------------------

해결 방법

누락된 타입 파라미터를 제공하면 돼요.

// Provide the missing type parameter
object Example:
  class Container[T]

  def process[T] = ???

  def test(): Unit =
    process[Container[Int]]

고차 종류(higher-kinded) 타입이 의도였다면, 메서드 시그니처를 바꾸면 돼요.

// Alternative: If higher-kinded type is intended, change the method signature
object Example:
  class Container[T]

  def process[F[_]] = ???

  def test(): Unit =
    process[Container]