CEP-0032: User-Defined Operator Overloading¶
Draft
Draft proposal for operator overloading beyond V1's closed contract-backed operator surface.
Summary¶
Catalyst should eventually decide whether users can overload operators beyond V1's closed contract-backed operator surface.
V1 does not support arbitrary custom operator overloading. Operator syntax is available only for accepted built-in forms and accepted prelude contract families.
Example¶
Possible future shape for an operator outside the accepted V1 surface:
impl Regex as Match(Text, bool) {
fn matches(self: *const Self, text: *const Text) bool {
return self.matches(text)
}
}
const ok = pattern =~ input
The proposal must decide whether future operator additions remain closed and contract-backed, or whether Catalyst ever allows broader user-defined symbolic operators.
Motivation¶
Operator overloading can make numeric, vector, matrix, range, parser, and domain code concise. It can also hide cost, allocation, dispatch, and surprising semantics.
Proposed Direction¶
The proposal should cover:
- which operators can be overloaded;
- whether overloads are semantic contract operations, inherent methods, or a separate mechanism;
- coherence and visibility rules;
- interaction with function overloading;
- diagnostics for ambiguity;
- performance and allocation visibility expectations.
Deferred Built-In Operator Candidates¶
Some future operators may be accepted as additional built-in spellings without opening arbitrary symbolic overloading.
Unary plus is deferred from V1:
+a
The future design should decide whether unary plus is accepted at all, whether it is primitive-only or contract-backed, whether it has a meaningful operation contract such as Pos(Out), and whether it can normalize, copy, convert, or otherwise transform a value. V1 rejects unary plus because it adds little expressiveness beside unary negation and risks becoming an implicit conversion hook.
V1 Compatibility¶
V1 keeps operator availability limited to accepted built-in forms and accepted contract-backed equality, ordering, indexing, iteration, and arithmetic behavior. Arbitrary symbolic operator overloading remains deferred.