Last active
September 23, 2016 06:51
-
-
Save purijatin/53ffaa8c1d485ed13b07256340099d51 to your computer and use it in GitHub Desktop.
New.scala
This file contains hidden or 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
To write a method which takes two type parameters and both should not be the same: | |
trait =!=[A,B] | |
implicit def neq[A,B]: =!=[A,B] = null | |
implicit def eqAmb[A]: =!=[A,A] = null | |
implicit def eqAmbig2[A]: =!=[A,A] = null | |
case class Foo2[A,B]( a: A, b: B )( implicit ev: A =!= B ) | |
//Foo2(1,2) compile error | |
case class Foo3[A,B]( a: A, b: B )( implicit ev: A =!= B, ev2: String =!= B, ev3: A =!= String ) | |
//above is for none of the type parameter to be String. You need to do at both the places | |
def notString[T](t : T)(implicit ev: T =!= String) = t | |
http://stackoverflow.com/questions/6909053/enforce-type-difference/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment