Last active
August 29, 2015 14:08
-
-
Save wheaties/ad27362732d73697d9bb to your computer and use it in GitHub Desktop.
Type Level Booleans
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 Boolean{ | |
def value: bool | |
} | |
case object True extends Boolean{ | |
val value = true | |
} | |
case object False extends Boolean{ | |
val value = false | |
} |
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
trait Or[X <: Boolean, Y <: Boolean]{ | |
type Out <: Boolean | |
def value: bool | |
} | |
object Or extends LowPriorityOr{ | |
def apply[X <: Boolean, Y <: Boolean](implicit or: Or[X, Y]): Aux[X, Y, or.Out] = or | |
implicit object OrFalse extends Or[False, False]{ | |
type Out = False | |
val value = false | |
} | |
} | |
trait LowPriorityOr{ | |
implicit OrTrue[X <: Boolean, Y <: Boolean] = new Or[X, Y]{ | |
type Out = True | |
val value = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment