Created
July 18, 2018 17:07
-
-
Save jeremyrsmith/64031d2116f10836580a740d40f62dcc to your computer and use it in GitHub Desktop.
HKT inference failure with DepFn and Aux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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