Created
November 5, 2015 12:24
-
-
Save yanns/930156648d5dd4cbbd51 to your computer and use it in GitHub Desktop.
Boolean in scala type
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 BoolType { | |
type Not <: BoolType | |
type Or[That <: BoolType] <: BoolType | |
} | |
sealed trait TrueType extends BoolType { | |
override type Not = FalseType | |
override type Or[That <: BoolType] = TrueType | |
} | |
sealed trait FalseType extends BoolType { | |
override type Not = TrueType | |
override type Or[That <: BoolType] = That | |
} | |
object BoolType { | |
type \/[A <: BoolType, B <: BoolType] = A#Or[B] | |
} | |
object BoolTypeSpecs { | |
import BoolType._ | |
implicitly[TrueType =:= TrueType] | |
implicitly[FalseType =:= FalseType] | |
implicitly[TrueType#Not =:= FalseType] | |
implicitly[FalseType#Not =:= TrueType] | |
implicitly[TrueType#Or[TrueType] =:= TrueType] | |
implicitly[TrueType#Or[FalseType] =:= TrueType] | |
implicitly[FalseType#Or[TrueType] =:= TrueType] | |
implicitly[FalseType#Or[FalseType] =:= FalseType] | |
implicitly[\/[TrueType, TrueType] =:= (TrueType \/ TrueType)] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment