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

Operator overloading? #2174

Closed
entropylost opened this issue Aug 23, 2024 · 1 comment
Closed

Operator overloading? #2174

entropylost opened this issue Aug 23, 2024 · 1 comment
Labels

Comments

@entropylost
Copy link

Is there any way to have operator overloading?

For example, if I have a vector type with a def (+) (a: Vector) (b: Vector): Vector, I'd like to be able to use it and other + definitions without having to do vector.+ everywhere.

This could be implemented by just making a list of function definitions and scanning until you find one that typechecks, but that might result in code instability. Alternatively, typeclasses could be used like haskell, although I feel like that'd be quite an effort to make.

@athas
Copy link
Member

athas commented Aug 24, 2024

There is no operator overloading in Futhark.

In the long term, we have considered adding type classes, but we haven't considered a specific design yet. I think we are waiting for OCaml to figure out how it fits nicely with a module system.

Local opens can be used to reduce the boilerplate slightly. Instead of x vector.+ y vector.+ z you could write vector.(x + y + z).

@athas athas added the question label Aug 24, 2024
@athas athas closed this as completed Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants