baml.ops.Equals

Equality that is an *equivalence relation*: reflexive (`x.eq(x)` is always true), symmetric, and transitive. There is no partial counterpart, so an implementor that cannot make equality reflexive should not implement this.

Reference version

Signature

interface baml.ops.Equals

Equality that is an equivalence relation: reflexive (x.eq(x) is always true), symmetric, and transitive. There is no partial counterpart, so an implementor that cannot make equality reflexive should not implement this.

Reflexivity is what lets == settle two references to the same value without inspecting it, so a non-reflexive eq is not merely surprising — it will not be consulted for x == x.

This is the interface a T extends baml.ops.Equals bound asks for, and the hook a type implements to be compared through dynamic dispatch — Python's __eq__, near enough. It is narrower than the == operator: baml.ops.equals_equals below compares any pair of compatible types and routes here only when the operand's runtime type implements this interface.

An implementation may panic, which throws never does not rule out; a caller working through a generic bound cannot enumerate the panics and must be ready for one it cannot describe. See baml.ops.Add.

Source:<builtin>/baml/ns_ops/comparison.bamlbytes 2474–3457

Required instance methods

function

eq

(self, other: Self) -> bool throws never

Whether self and other are equal.

other is typed Self, so an implementation only ever compares a type against itself; there is no heterogeneous equality. Implementations must be reflexive, symmetric and transitive — Rust's Eq, not PartialEq: the float impl keeps the law by making NaN equal to itself rather than agreeing with IEEE.

Default instance methods

function

neq

(self, other: Self) -> bool throws never

Whether self and other differ. Defaults to !self.eq(other).

Override this only to compute the answer more directly; an override that disagrees with !eq leaves the pair inconsistent. Equals for null overrides it with a constant false, which is consistent because null has exactly one value.