-
Notifications
You must be signed in to change notification settings - Fork 22
Closed
Description
import scala.language.higherKinds
final case class Getter[S, A](get: S => A)
final case class Wrap[F[_], A](value: F[A])
object Wrap {
// Helper to defer specifying second argument to Wrap.
// Basically a type lambda specialized for Wrap.
// Wr[F]#ap[A] =:= Wrap[F, A]
type Wr[F[_]] = { type ap[A] = Wrap[F, A] }
implicit def unwrapper[F[_], A]: Getter[Wrap[F, A], F[A]] =
Getter(w => w.value)
}
object Test {
import Wrap._
type Foo[A] = List[A]
type Bar[A] = String
type WrapFoo1[A] = Wrap[Foo, A]
type WrapBar1[A] = Wrap[Bar, A]
implicitly[Getter[WrapFoo1[Int], Foo[Int]]] // OK
implicitly[Getter[WrapBar1[Int], Bar[Int]]] // OK
type WrapFoo2[A] = Wr[Foo]#ap[A]
type WrapBar2[A] = Wr[Bar]#ap[A]
// here's evidence that the new types are the same as the old ones
implicitly[WrapFoo2[Int] =:= WrapFoo1[Int]]
implicitly[WrapBar2[Int] =:= WrapBar1[Int]]
// but implicit resolution doesn't work as before
implicitly[Getter[WrapFoo2[Int], Foo[Int]]] // OK
implicitly[Getter[WrapBar2[Int], Bar[Int]]] // error: could not find implicit value for parameter
// e: Getter[Test.WrapBar2[Int],Test.Bar[Int]]
}Note that it is the combination of type alias with phantom type parameter (type Bar[A] = String) and type lambda (Wr[Bar]#ap) that is problematic. Each of the three simpler cases works.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels