Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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]
Add Comment
Please, Sign In to add comment