Status of custom infix operators?

Reading through the forum and GitHub issues I get the impression that custom infix operators are maybe? going to be supported?

I understand the reluctance on this feature as I feel they’re often overused in other languages, leading to harder to understand code.

One use case where I found them useful is infix operators of Unicode characters for familiar mathematical symbols, for example union and intersection of sets (∪, ∩). In these cases I usually make the Unicode operators aliases of existing functions with textual names for the operation (“union”, “intersection”).

Is there any chance this limited form of infix operator could be supported?

I’ve never seen any indications that the ReScript team would support custom infix ops. Would you mind pointing to where you saw that?

Probably a misreading on my part after scanning numerous messages and issues.

It looks like non-alphabetic characters like “∩” aren’t legal ReScript syntax even for prefix functions, so my idea is doubly unlikely.

Adding complexity to the core language would be a hard sell.
What might be possible to explore, is per-file infix operators, i.e. just a locally different way of parsing/printing the ast, with no changes required outside the parser/printer, and purely opt-in.

For example, a directive in the file indicating to show plus as +++. So no need to look outside the file to know what +++ means. And no difference to users of the file which would continue to see it as plus.

Fair enough, thanks.

What are the rules around using Unicode characters in identifiers? I think even alternate letter forms are a syntax error?

See proof of concept here: Proof of Concept: explore per-file custom infix operators. by cristianoc · Pull Request #6076 · rescript-lang/rescript-compiler · GitHub

2 Likes