Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language: Allow seperate definitions of prefix, infix and postfix #2026

Open
spotandjake opened this issue Feb 14, 2024 · 0 comments
Open

Language: Allow seperate definitions of prefix, infix and postfix #2026

spotandjake opened this issue Feb 14, 2024 · 0 comments

Comments

@spotandjake
Copy link
Member

spotandjake commented Feb 14, 2024

Currently, we can't support an operator like -n as we already define the operator as an infix operator.

Proposal A

I suggest to support this we make it like the following:

provide let (-) = (a, b) => tagSimpleNumber(Wasmi32.add(untagSimpleNumber(a), untagSimpleNumber(b)))

@prefix
provide let (-) = (a) => a * -1

@postfix
provide let (-) = (a) => decr(a)

we could then replace the function names with in the case of @prefix we could make it $(-) and in the case of @postfix we could make it (-)$ as grain doesn't allow $ in idents, this ensures that we won't overwrite a user var or function while providing each definition a unique name to avoid needing operator overloading.

Proposal B

Instead of requiring a user decorator on the function we could only allow an operator to be, infix and prefix or postfix but never both prefix and postfix. In this scenario we could determine that you are writing the prefix or postfix implementation as it would only take a single variable. Without rewriting a lot of semantics in the compiler we would probably be best still using the name override. The downfall of this approach, is while its simplier it narrows what the user can do.

Problem:
One thing that we certainly need to figure out here would be the semantics of from Module use { and Module.(-)(x, y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant