Identity equality checks in Pony are done via the is keyword. is verifies that the two items are the same.
ifNoneisNonethen// TRUE!// There is only 1 None so the identity is the sameendleta=Foo("hi")letb=Foo("hi")ifaisbthen// NOPE. THIS IS FALSEendletc=aifaiscthen// YUP! TRUE!end
Structural equality checking in Pony is done via the infix operator ==. It verifies that two items have the same value. If the identity of the items being compared is the same, then by definition they have the same value.
You can define how structural equality is checked on your object by implementing fun eq(that: box->Foo): Bool. Remember, since == is an infix operator, eq must be defined on the left operand, and the right operand must be of type Foo.
classFoolet_a:Stringnewcreate(a:String)=>_a=afuneq(that:box->Foo):Bool=>this._a==that._aactorMainnewcreate(e:Env)=>leta=Foo("hi")letb=Foo("bye")letc=Foo("hi")ifa==bthen// won't printe.out.print("1")endifa==cthen// will printe.out.print("2")endifaiscthen// won't printe.out.print("3")end
If you don’t define your own eq, you will inherit the default implementation that defines equal by value as being the same as by identity.