Skip to content

Precedence and associativity of the @ operator is undocumented #70

@roboz0r

Description

@roboz0r

The @ symbol is permitted as the first character of a custom operator.

let (@+) a b = a + b
1 @+ 2

regexp first-op-char = !%&*+-./<=>@^|~

The precedence table, doesn't list the @ operator to define its precedence and associativity.

### Precedence of Symbolic Operators and Pattern/Expression Constructs
Rules of precedence control the order of evaluation for ambiguous expression and pattern
constructs. Higher precedence items are evaluated before lower precedence items.
The following table shows the order of precedence, from highest to lowest, and indicates whether
the operator or expression is associated with the token to its left or right. The `OP` marker represents
the `symbolic-op` tokens that begin with the specified prefix, except those listed elsewhere in the
table. For example, `+OP` represents any token that begins with a plus sign, unless the token appears
elsewhere in the table.
| Operator or expression | Associativity | Comments |
| --- | --- | --- |
| f<types> | Left | High-precedence type application; see [§](lexical-filtering.md#lexical-analysis-of-type-applications) |
| f(x) | Left | High-precedence application; see [§](lexical-filtering.md#high-precedence-application) |
| . | Left | |
| _prefix-op_ | Left | Applies to prefix uses of these symbols |
| "| rule" | Right Pattern matching rules |
| "f x" <br> "lazy x" <br> "assert x" | Left | |
| **OP | Right | |
| *OP /OP %OP | Left | |
| - OP +OP | Left | Applies to infix uses of these symbols |
| :? | Not associative | |
| :: | Right | |
| ^OP | Right | |
| !=OP \<OP \>OP = \|OP &OP $ | Left | |
| :> :?> | Right | |
| & && | Left | |
| or \|\| | Left | |
| , | Not associative | |
| := | Right | |
| -> | Right | |
| if | Not associative | |
| function, fun, match, try | Not associative | |
| let | Not associative | |
| ; | Right | |
| \| | Left | |
| when | Right | |
| as | Right | |

The categorization table doesn't list @ operator.

### Categorization of Symbolic Operators
The following `symbolic-op` tokens can be used to form prefix and infix expressions. The marker `OP`
represents all `symbolic-op` tokens that begin with the indicated prefix, except for tokens that appear
elsewhere in the table.
```fsgrammar
infix-or-prefix-op :=
+, -, +., -., %, &, &&
prefix-op :=
infix-or-prefix-op
~ ~~ ~~~ (and any repetitions of ~)
!OP (except !=)
infix-op :=
infix-or-prefix-op
- OP +OP || <OP >OP = |OP &OP ^OP *OP /OP %OP !=
(or any of these preceded by one or more ‘.’)
:=
::
$
or
?
```

What would be the best way to determine this to update the spec?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions