Std. Equatable
(Cure Standard Library v0.37.2)
View Source
Equality: the Equatable(t) interface behind ==, its instances for
Int, Float, Bool, Atom, Nat, Option(t) and List(t), and the
derived !=.
The Equatable(t) protocol mirrors the built-in == operator but can be
implemented for user-defined types so generic algorithms stay polymorphic.
The minimal basis is a single primitive method, `==`; `!=` is a
derived, where-constrained top-level function (not (a == b)), written
without the operator to avoid regress. It is a standalone function rather
than an interface default so it is never specialized per instance (an
instance-specialised default that re-dispatches `==` at a concrete
operand cannot be elaborated for every leaf today).
(This is the comparison protocol — "can these two values be checked
for equality?". It is unrelated to Equivalent, the identity type
whose values are proofs that two things are equal.)
Examples
use Std.Equatable
`==`(1, 1) # => true
`!=`(1, 2) # => true
`==`(:ok, :ok) # => true
Summary
Callbacks
Group tag consumed by Cure.Stdlib.Preload.
Equality between two t values. Sole primitive obligation of the class.
Functions
Inequality derived from `==`. The where Equatable(t) constraint
threads the dictionary that dispatches `==` at the caller's type.
true when a equals b. The return type is spelled as the qualified
Std.Bool.Bool (not bare Bool) so it denotes the ambient boolean in
EVERY implementing module — including one that shadows the prelude with a
local type Bool = .... A bare Bool re-resolves in the consumer's scope
and would bind to that local shadow, so an auto-derived structural ==
(whose Std.Builtin.struct_eq body returns Std.Bool#Bool) could not
satisfy the interface signature there.
Callbacks
Functions
fn !=(a: t, b: t) -> Bool
Inequality derived from `==`. The where Equatable(t) constraint
threads the dictionary that dispatches `==` at the caller's type.
fn ==(a: t, b: t) -> Std.Bool.Bool
true when a equals b. The return type is spelled as the qualified
Std.Bool.Bool (not bare Bool) so it denotes the ambient boolean in
EVERY implementing module — including one that shadows the prelude with a
local type Bool = .... A bare Bool re-resolves in the consumer's scope
and would bind to that local shadow, so an auto-derived structural ==
(whose Std.Builtin.struct_eq body returns Std.Bool#Bool) could not
satisfy the interface signature there.