Back to Scala3

E043: Unreducible Application

docs/_docs/reference/error-codes/E043.md

3.8.41.7 KB
Original Source

E043: Unreducible Application

This error is emitted when an abstract type constructor (higher-kinded type) is applied to wildcard type arguments.

Such applications are equivalent to existential types, which are not supported in Scala 3. An abstract type constructor cannot be applied to wildcard arguments because the compiler cannot determine what concrete type would result.


Example

scala
trait Container[F[_]]:
  def create: F[?]

Error

scala
-- [E043] Type Error: example.scala:2:14 ---------------------------------------
2 |  def create: F[?]
  |              ^^^^
  |     unreducible application of higher-kinded type F to wildcard arguments
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | An abstract type constructor cannot be applied to wildcard arguments.
  | Such applications are equivalent to existential types, which are not
  | supported in Scala 3.
   -----------------------------------------------------------------------------

Solution

scala
// Use a concrete type argument
trait Container[F[_]]:
  def create[A]: F[A]
scala
// Or use a type member
trait Container[F[_]]:
  type Element
  def create: F[Element]
scala
// Or make the type concrete in implementations
trait Container[F[_]]:
  def create: F[Int]
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>