Skip to content

Instantly share code, notes, and snippets.

@jeremyrsmith
Created July 18, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyrsmith/64031d2116f10836580a740d40f62dcc to your computer and use it in GitHub Desktop.
Save jeremyrsmith/64031d2116f10836580a740d40f62dcc to your computer and use it in GitHub Desktop.
HKT inference failure with DepFn and Aux
import scala.language.higherKinds
trait Foo[A] {
type Out[_]
def apply[T](t: T): Out[T]
}
object Foo {
type Aux[A, Out0[_]] = Foo[A] { type Out[A] = Out0[A] }
implicit val fooInt: Aux[Int, List] = new Foo[Int] {
type Out[A] = List[A]
def apply[T](t: T): List[T] = List(t)
}
implicit val fooString: Aux[String, Option] = new Foo[String] {
type Out[A] = Option[A]
def apply[T](t: T): Option[T] = Option(t)
}
}
def works[A, T](a: A, t: T)(implicit
foo: Foo[A]
): foo.Out[T] = foo(t)
def fails[A, FooOut[_], T](a: A, t: T)(implicit
foo: Foo.Aux[A, FooOut]
): FooOut[T] = foo(t)
works(10, true)
// res0: Foo.fooInt.Out[Boolean] = List(true)
fails(10, true)
// error: could not find implicit value for parameter foo: Foo.Aux[Int,FooOut]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment