Violet

← Docs

User-defined operators

Infix operators with associativity and precedence, declared at the top level.

Syntax

\operator "\x * \y" => mul
  \associativity: \left
  \stronger_than: +

Associativity

You can say an operator associativity is \left, \right, or \none.

Precedence

You can use \stronger_than, \weaker_than, \same_as to tell compiler how to deal with priority of operators.

Example: + and *

\operator "\x + \y" => add
  \associativity: \left

\operator "\x * \y" => mul
  \stronger_than: +
  \associativity: \left

Example: equality as an operator

\operator "\x = \y" => Id x y
  \associativity: \left