I was trying to work out some simple examples of type-level programming in Scala 2.11. Here is a function to tell type equality:
def type_==[A, B](implicit ev: A =:= B = null) = ev != null Here =:= is defined in the prelude, but for our purpose, even a simple definition such as
class =:=[A, B] implicit def equalTypeInstance[A] = new =:=[A, A] would do. To be sure, can do
type_==[Int, String] // false type_==[Int, Int] // true Next, I encode booleans as types - to make things simple, I avoid to define any operation
sealed trait Bool trait True extends Bool trait False extends Bool I can again check that
type_==[True, True] // true So I thought I might convert Bool to Boolean by doing
def bool2boolean[A <: Bool] = type_==[A, True] Here's the catch:
bool2boolean[True] // false Can anyone explain the reason why?