Skip to content

Instantly share code, notes, and snippets.

@yanns
Created November 5, 2015 12:24
Show Gist options
  • Save yanns/930156648d5dd4cbbd51 to your computer and use it in GitHub Desktop.
Save yanns/930156648d5dd4cbbd51 to your computer and use it in GitHub Desktop.
Boolean in scala type
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