Open
Description
reproduction steps
using Scala 2.13.x,
type Foo[F[_], A, B] = Kleisli[F, A, B]
val foo: Foo[Option, Int, Int] = Kleisli { i => Option(i) }
implicit class FooOps[F[_], A, B](val foo: Foo[F, A, B]) {
def bar(a: A): F[B] = foo.run(a)
}
foo.bar(1) //does not compile
or see scastie snippet here https://scastie.scala-lang.org/uIri16dwQWWatxSnNyTBVg
problem
The compiler fails with value bar is not a member of...
:
I found 2 ways of removing this error, either defining the implicit class using the the type being aliased:
implicit class FooOps2[F[_], A, B](val foo: Kleisli[F, A, B]) extends AnyVal {
def bar2(a: A): F[B] = foo.run(a)
}
foo.bar2(1) //compiles
or by including the contravariance of Kleisli's second type param in the type alias too:
type Foo[F[_], -A, B] = Kleisli[F, A, B] // `-` included on the `A`!
val foo: Foo[Option, Int, Int] = Kleisli { i => Option(i) }
implicit class FooOps[F[_], A, B](val foo: Foo[F, A, B]) {
def bar(a: A): F[B] = foo.run(a)
}
foo.bar(1) //compiles
The compiler error was quite unhelpful in debugging this issue.