Last active
November 24, 2015 01:18
-
-
Save hgiddens/a1db16b659324f8d21aa to your computer and use it in GitHub Desktop.
Inject + PDTs
This file contains hidden or 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 scalaz.{Coproduct, Inject} | |
| trait X { self ⇒ | |
| type O[Z] | |
| def :+:(that: X): X { type O[Z] = Coproduct[that.O, self.O, Z] } = | |
| new X { type O[Z] = Coproduct[that.O, self.O, Z] } | |
| } | |
| object X { | |
| def apply[F[_]]: X { type O[Z] = F[Z] } = | |
| new X { type O[Z] = F[Z] } | |
| } | |
| trait A[Z] | |
| trait B[Z] | |
| trait C[Z] | |
| object App extends App { | |
| type O1[Z] = Coproduct[B, C, Z] | |
| type O[Z] = Coproduct[A, O1, Z] | |
| val x = X[A] :+: X[B] :+: X[C] | |
| implicitly[O[Int] =:= x.O[Int]] // Fine | |
| Inject[A, O] // Fine | |
| Inject[A, x.O] // Fails; could not find implicit value for parameter I: Inject[A, x.0] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment