Scala中类型不相等的证据

Scala中类型不相等的证据,scala,types,shapeless,implicits,Scala,Types,Shapeless,Implicits,有没有办法约束一个方法,使其仅在两种类型被证明不相等时才有意义 trait Something[A, B] { // I can only be called if type A is the same as type B def ifEqual(implicit ev: A =:= B) // Now I cannot be called if type A is proven to be the same as type B def ifNotEqual(implicit

有没有办法约束一个方法,使其仅在两种类型被证明不相等时才有意义

trait Something[A, B] {
  // I can only be called if type A is the same as type B
  def ifEqual(implicit ev: A =:= B)

  // Now I cannot be called if type A is proven to be the same as type B
  def ifNotEqual(implicit ev: A ??? B)
}
对。从


像往常一样,令人惊叹的类型富!这一定是一个复制品,除了它很酷迈尔斯介入回答它。就像安妮·霍尔(Annie Hall)在马歇尔·麦克卢汉(Marshall McLuhan)出现在电影台词中的那一幕。“要是生活就是这样就好了!”完全是重复的。看见
// Type inequalities
trait =:!=[A, B] 

implicit def neq[A, B] : A =:!= B = new =:!=[A, B] {}
implicit def neqAmbig1[A] : A =:!= A = ???
implicit def neqAmbig2[A] : A =:!= A = ???