Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala equality with type checking?

Is there a uniform method to perform equality with type checking? Unfortunately

val objectA:String = "test"
val objectB:Int = 2
objectA == objectB

the equality operator == doesn't complain if objectB is a Int while objectA is a String. I would need an operator like === that perform type checking as well (and I hope it is uniform to all scala obj). Does such operator exist?

like image 264
Matroska Avatar asked Jan 31 '12 17:01

Matroska


1 Answers

You need to look at scalaz's === for type-safe equals - it's implemented as type class there.

You can also watch talk by Heiko Seeberger, where he describes how it's implemented:

http://days2011.scala-lang.org/node/138/275

You can also find some examples here:

http://scalaz.github.com/scalaz/scalaz-2.9.1-6.0.4/doc.sxr/scalaz/example/ExampleEqual.scala.html#24187

(in the examples they are using method, but it's simply alias for ===)

like image 178
tenshi Avatar answered Sep 28 '22 01:09

tenshi