You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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).
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 dovector.+
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.
The text was updated successfully, but these errors were encountered: