Skip to content

Instantly share code, notes, and snippets.

@hgiddens
Last active November 24, 2015 01:18
Show Gist options
  • Select an option

  • Save hgiddens/a1db16b659324f8d21aa to your computer and use it in GitHub Desktop.

Select an option

Save hgiddens/a1db16b659324f8d21aa to your computer and use it in GitHub Desktop.
Inject + PDTs
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