Last active
February 27, 2016 13:57
-
-
Save jto/3d3d91f39e4520800a76 to your computer and use it in GitHub Desktop.
This file contains 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
sealed class Match[A, B] { type τs <: HList } | |
object Match { | |
type Aux[A0, B0, τ0 <: HList] = Match[A0, B0] { type τs = τ0 } | |
sealed trait τ | |
sealed trait τ1[A] | |
implicit def matchEq[A0]: Aux[A0, A0, HNil] = | |
new Match[A0, A0]{ | |
type τs = HNil | |
} | |
implicit def match0[A0]: Aux[τ, A0, A0 :: HNil] = | |
new Match[τ, A0] { type τs = A0 :: HNil } | |
implicit def matchTC[F[_], TC[_[_]]]: Aux[TC[τ1], TC[F], F[τ] :: HNil] = | |
new Match[TC[τ1], TC[F]] { type τs = F[τ] :: HNil } | |
implicit def match1[F[_], A, B](implicit m0: Match[A, B]): Aux[F[A], F[B], m0.τs] = | |
new Match[F[A], F[B]] { type τs = m0.τs } | |
implicit def match2[F[_, _], A0, A1, B0, B1, τs0 <: HList, τs1 <: HList](implicit m0: Aux[A0, B0, τs0], m1: Aux[A1, B1, τs1], p: Prepend[τs0, τs1]): Aux[F[A0, A1], F[B0, B1], p.Out] = | |
new Match[F[A0, A1], F[B0, B1]] { type τs = p.Out } | |
def apply[A, B](implicit m: Match[A, B]): Aux[A, B, m.τs] = m | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Matching Functor:
I'm not super satisfied by
τs
beingList[τ] :: HNil
thought.