Created
February 16, 2016 16:05
-
-
Save wheaties/c50c9a62fb16ff2eceaa to your computer and use it in GitHub Desktop.
Add type level boolean to OneOf
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
| trait OneOfProof[Obj, Types] { | |
| type Cond <: Bool | |
| } | |
| object OneOfProof extends OneOfProof1{ | |
| implicit def left[Obj, R]: Aux[Obj, Obj | R, True] = new OneOfProof[Obj, Obj | R] { type Cond = True } | |
| } | |
| trait OneOfProof1 extends OneOfProof2{ | |
| implicit def right[Obj, L]: Aux[Obj, L | Obj, True] = new OneOfProof[Obj, L | Obj] { type Cond = True } | |
| } | |
| trait OneOfProof2 extends OneOfProof3{ | |
| implicit def recur[Obj, L, R](implicit proof: OneOfProof[Obj, R]): Aux[Obj, L | R, proof.Cond] = | |
| new OneOfProof[Obj, L | R] { type Cond = proof.Cond } | |
| } | |
| trait OneOfProof3{ | |
| type Aux[O, T, C <: Bool] = OneOfProof[O, T]{ type Cond = C } | |
| implicit def nt[Obj, L, R](implicit has: Aux[Obj, L | R, True]): Aux[Obj, L | R, False] = ??? | |
| implicit def fail[Obj, L, R]: Aux[Obj, L | R, False] = new OneOfProof[Obj, L | R] { type Cond = False } | |
| } |
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
| package object lala{ | |
| type |[A, B] = (A, B) | |
| sealed trait Bool | |
| sealed trait True extends Bool | |
| sealed trait False extends Bool | |
| type OneOf[Obj, Types] = OneOfProof.Aux[Obj, Types, True] | |
| type NotOneOf[Obj, Types] = OneOfProof.Aux[Obj, Types, False] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment