Created
October 31, 2014 02:52
-
-
Save wheaties/0263940a7f04cb6e0da2 to your computer and use it in GitHub Desktop.
Type Contains
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 trait TList | |
case object TNil extends TList | |
case class <+>[A, B <: TList]() extends TList //some weird symbol for :: | |
trait Contains[A, TL <: TList] | |
object Contains extends LowPriorityContains{ | |
def apply[A, TL <: TList](implicit cnt: Contains[A, TL]) = cnt | |
implicit def has[F[_], A, T <: TList] = new Contains[F, F[A] <+> T]{} | |
implicit def has[F[_], H, T <: TList](implicit cnt: Contains[F, T]) = new Contains[F, H :: T]{} | |
} | |
trait LowPriorityContains{ | |
implicit def has[A, T <: TList] = new Contains[A, A <+> T]{} | |
implicit def recur[A, H, T <: TList](implicit cnt: Contains[A, T]) = new Contains[A, H <+> T]{} | |
} | |
//Next question, does it work on higher kinded types? List[_] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment