Skip to content

Instantly share code, notes, and snippets.

@wheaties
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save wheaties/e54bd081b2cb88b5e4b7 to your computer and use it in GitHub Desktop.

Select an option

Save wheaties/e54bd081b2cb88b5e4b7 to your computer and use it in GitHub Desktop.
trait Projection[P <: Poly]{
def apply[A, B](a: A, b: B)(implicit law:Law[P, A, B]): law.Out = law(a, b)
}
//Witnessing that P can handle AxB -> O, AxO, BxO
//i.e. P is a projection onto a line
trait Law[P <: Poly, A, B]{
type Out
def apply(a: A, b: B): Out
}
object Law{
def apply[P <: Poly, A, B](implicit law: Law[P, A, B]) = law
implicit def mk[P <: Poly, A, B, O](implicit ev: Case2.Aux[P, A, B, O], rq: Case2[P, A, O], rq2: Case2[P, B, O]) =
new Law[P, A, B]{
type Out = ev.Result
def apply(a: A, b: B) = ev(a, b)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment