Skip to content

Operator Fixity

A fixity declaration, introduced by the syntax keyword followed by fixity, defines an operator's precedence and associativity. The syntax varies based on the operator's arity, associativity, and precedence.

  • Arity declaration of an operator with no precedence or associativity:
syntax fixitiy <name> := <arity>;

Where <arity> is either unary or binary.

This is equivalent to:

syntax fixitiy <name> := <arity> {};
  • Associativity declaration of an operator with no precedence:
syntax fixitiy <name> := <arity> { assoc := <associativity> };

Where <associativity> is either left, right, or none.

  • Precedence declaration of an operator with no associativity:

  • Equal precedence to another operator:

syntax fixitiy <name> := <arity> { same := otherOperatorName };
  • Higher precedence than other operators:
syntax fixitiy <name> := <arity> {
    above := [otherOperatorName1;...; otherOperatorNameN] };
  • Lower precedence than other operators:
syntax fixitiy <name> := <arity> {
    below := [otherOperatorName1;...; otherOperatorNameN] };
  • Associativity and precedence declaration of an operator:
syntax fixitiy <name> := <arity> {
    assoc := <associativity>;
    above := [otherOperatorName1;...; otherOperatorNameN]
    };

Examples of Fixity Declarations

Below are a few common fixity declarations for operators in Juvix's standard library.

syntax fixity rapp := binary {assoc := right};
syntax fixity lapp := binary {assoc := left; same := rapp};
syntax fixity seq := binary {assoc := left; above := [lapp]};

syntax fixity functor := binary {assoc := right};

syntax fixity logical := binary {assoc := right; above := [seq]};
syntax fixity comparison := binary {assoc := none; above := [logical]};

syntax fixity pair := binary {assoc := right};
syntax fixity cons := binary {assoc := right; above := [pair]};

syntax fixity step := binary {assoc := right};
syntax fixity range := binary {assoc := right; above := [step]};

syntax fixity additive := binary {assoc := left; above := [comparison; range; cons]};
syntax fixity multiplicative := binary {assoc := left; above := [additive]};

syntax fixity composition := binary {assoc := right; above := [multiplicative]};