What i think would be a neat addition to the language are the monoid operators `(+)`

and `(*)`

.

This would use two traits: `MonoidAdd`

and `MonoidMul`

. Both traits define the operator function and an id function.

Why? Monoids are extremely useful. Most objects we deal with while programming can be expressed as monoids. This would give us two dedicated all purpose operators for library code, which would (imo) be a sweet spot between an explosion of domain specific operators and misuse of existing operators for other purposes.

Why two monoids? Several reasons. There are some semantic connotations with `(+)`

and `(*)`

, so libs can choose the most fitting one. For example list concatenation would use `(+)`

. Matrix multiplication would use `(*)`

.

Also, there are often more then one important operations that can be used in a monoid. And most importantly, this would allow the definition of a ring structure. I would imagine a library to augment this traits with traits for things like commutativity and additional mathematical structures like groups and rings and a bunch of general methods to operate on said structures.

Why the tokens `(+)`

and `(*)`

? An obvious alternative for the first one would be `++`

. But `**`

is problematic because infix `*`

before prefix `*`

is already legal (for example `2**&2`

). Also i quite like how `(+)`

resembles the mathematical notation of circled plus and multiplication.

I think this would get us a lot of bang for the buck in terms of generality. The cost would be the introduction of a fairly mathy concept into the language and one could argue that that is not very inclusive to people without formal computer science education. On the other hand, in other areas rust doesn’t shy away from theory when its useful and everyone who has studied one or two semesters of computer science, engineering or any other math-adjacent course has seen this before. And “use `(+)`

to concatenate lists and to merge sets” doesn’t require theoretical understanding.

Sorry for the wall of text. If there is any interest in that, i could open a tread.