Skip to content

Add more (infix) operators#1091

Merged
dvdvgt merged 18 commits intomainfrom
more-operators
Mar 18, 2026
Merged

Add more (infix) operators#1091
dvdvgt merged 18 commits intomainfrom
more-operators

Conversation

@b-studios
Copy link
Copy Markdown
Collaborator

@b-studios b-studios commented Jul 22, 2025

This PR adds a few more infix operators. This is mostly just lexing and parsing so doesn't come with a lot of conceptual cost for the implementation.

A few things are not clear / implemented:

  • we should name things consistently (I actually would like to rename infixAdd to InfixPlus, but this will break a lot of things)
  • is this slowing down the parser? (for precedence it is now deeply nested)
  • is the precedence ok?
  • should pipe left and right be by-name? This might open up some cool usages.
  • right now the new tokens are added as one batch, we might want to clean them up by sorting them somehow
  • I didn't add a === b and a !== b since the tokens === are already used to represent ==, ahhh.

@b-studios b-studios marked this pull request as ready for review July 28, 2025 15:17
case _ =>
val lhs = variable()
peek.kind match {
case `+=` | `-=` | `*=` | `/=` =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about <<= and >>=?

Copy link
Copy Markdown
Collaborator

@dvdvgt dvdvgt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to make some changes in the Effekt meeting. Thanks!

Comment thread effekt/shared/src/main/scala/effekt/Lexer.scala Outdated
Comment thread effekt/shared/src/main/scala/effekt/Parser.scala Outdated
Comment thread effekt/shared/src/main/scala/effekt/Parser.scala Outdated
@marvinborner
Copy link
Copy Markdown
Member

bump

also, what do you think about a := operator? I'd like to use it to overwrite assignments e.g. for references like here

@marvinborner
Copy link
Copy Markdown
Member

If you're already working on this, could you also support infixConcat for lists, arrays, etc.?

@dvdvgt
Copy link
Copy Markdown
Collaborator

dvdvgt commented Mar 11, 2026

I implemented the required changes. I also want to note that currently +=, -=, *=, /= are hardcoded to be transformed to an assignment to local variables. For example

var x = 1
x += 1

is parsed as

var x = 1
x = x + 1

This is of course convenient but precludes us from overloading these operators in the future.

Furthermore, I also added the infix operator r := x and overloaded it for global references Ref[T] to have the semantics of r.set(x). Additionally, l ++ other is now an alias for l.append(other), where both l: List[T] and other: List[T].

I refrained from overloading these new operators for any other types as this already is a pretty "bikeshed-able" PR as it is.

@dvdvgt
Copy link
Copy Markdown
Collaborator

dvdvgt commented Mar 11, 2026

Also, this most definitely will break the communities builds if there any overloads for the renamed infix operators.

Comment thread examples/normalizer/simple.effekt Outdated
Comment thread effekt/shared/src/main/scala/effekt/core/optimizer/Deadcode.scala Outdated
Comment thread effekt/shared/src/main/scala/effekt/Parser.scala Outdated
Comment thread effekt/shared/src/main/scala/effekt/Precedence.scala Outdated
Copy link
Copy Markdown
Contributor

@jiribenes jiribenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I'm not a fan of many of the extra operators chosen, the implementation itself seems reasonable and extensible in the future, so I'm fine with merging this.

This will likely break a lot of existing Effekt code, but the fix is just simple string replacement, so it's fine.

@dvdvgt dvdvgt merged commit da69e03 into main Mar 18, 2026
8 checks passed
@dvdvgt dvdvgt deleted the more-operators branch March 18, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants