Skip to content

Poly function argument inhibits type inference #14605

Open
@Adam-Vandervorst

Description

@Adam-Vandervorst

Compiler version

3.1.3-RC1-bin-20220218-29f9d33-NIGHTLY

Minimized code

def poly_rec[F[_], G[_], A](nt: [X] => F[X] => G[X])(xs: List[F[A]]): List[G[A]] = xs match
  case Nil => Nil
  case x::xs => nt(x) +: poly_rec(nt)(xs) // doesn't work
//  case x::xs => nt(x) +: poly_rec[F, G, A](nt)(xs) // works

def rec[F[_], G[_], A](nt: F[A] => G[A])(xs: List[F[A]]): List[G[A]] = xs match
  case Nil => Nil
  case x::xs => nt(x) +: rec(nt)(xs)

Output

  case x::xs => nt(x) +: poly_rec(nt)(xs)
                                  ^^
Found:    (nt : scala.this.PolyFunction{apply[X](x$1: F[X]): G[X]})
Required: scala.this.PolyFunction{apply[X](x$1: scala.this.Nothing): scala.this.Any}

Expectation

Work like the second function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions