Can I make own functions for symbols (+), (*)

For example I want to have multiply for my type

module Vector = {
  type t = (float, float)
  let (+) => ((ax, ay), (ba, by)) => (ax + bx, ay + by)
}

As far as I know you can’t define custom infix operators in ReScript yet (although it seems to be planned for v10: Roadmap | ReScript Community ).
There is the syntax with slash and quotes \":+:" that can be used for function symbols, but it doesn’t work as infix notation.

However, this does seem to compile:

let \"+" = (x, y) => x +. y

Js.log(2.0 + 4.0)

Playground link

Which suggests to me that you can overwrite function symbols that already work as infix operators in ReScript.

4 Likes

Thank you! As I understand I will be able to create own operators, like :+: from your example.
If ReScript will has feature overload [] it will cool.