Skip to content

Commit 3dbc6c4

Browse files
authored
Update operator-overloading.md (#47633)
- Add output result for code block - Improve consistency by highlighting the `+!` operator - Fix a missing space between words
1 parent ab5e746 commit 3dbc6c4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

docs/fsharp/language-reference/operator-overloading.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ The following code illustrates a vector class that has just two operators, one f
3131

3232
[!code-fsharp[Main](~/samples/snippets/fsharp/lang-ref-2/snippet4001.fs)]
3333

34+
**Output:**
35+
36+
```console
37+
1 2
38+
2 4
39+
2 4
40+
-2 -4
41+
```
42+
3443
## Creating New Operators
3544

3645
You can overload all the standard operators, but you can also create new operators out of sequences of certain characters. Allowed operator characters are `!`, `$`, `%`, `&`, `*`, `+`, `-`, `.`, `/`, `<`, `=`, `>`, `?`, `@`, `^`, `|`, and `~`. The `~` character has the special meaning of making an operator unary, and is not part of the operator character sequence. Not all operators can be made unary.
@@ -91,7 +100,7 @@ The following table shows the standard operators and their corresponding generat
91100

92101
Note that the `not` operator in F# does not emit `op_Inequality` because it is not a symbolic operator. It is a function that emits IL that negates a boolean expression.
93102

94-
Other combinations of operator characters that are not listed here can be used as operators and have names that are made up by concatenating names for the individual characters from the following table. For example, +! becomes `op_PlusBang`.
103+
Other combinations of operator characters that are not listed here can be used as operators and have names that are made up by concatenating names for the individual characters from the following table. For example, `+!` becomes `op_PlusBang`.
95104

96105
|Operator character|Name|
97106
|------------------|----|
@@ -122,7 +131,7 @@ Other combinations of operator characters that are not listed here can be used a
122131

123132
*Prefix* operators are expected to be placed in front of an operand or operands, much like a function. *Infix* operators are expected to be placed between the two operands.
124133

125-
Only certain operators can be used as prefix operators. Some operators are always prefix operators, others can be infix or prefix, and the rest are always infix operators. Operators that begin with `!`, except `!=`, and the operator `~`, or repeated sequences of`~`, are always prefix operators. The operators `+`, `-`, `+.`, `-.`, `&`, `&&`, `%`, and `%%` can be prefix operators or infix operators. You distinguish the prefix version of these operators from the infix version by adding a `~` at the beginning of a prefix operator when it is defined. The `~` is not used when you use the operator, only when it is defined.
134+
Only certain operators can be used as prefix operators. Some operators are always prefix operators, others can be infix or prefix, and the rest are always infix operators. Operators that begin with `!`, except `!=`, and the operator `~`, or repeated sequences of `~`, are always prefix operators. The operators `+`, `-`, `+.`, `-.`, `&`, `&&`, `%`, and `%%` can be prefix operators or infix operators. You distinguish the prefix version of these operators from the infix version by adding a `~` at the beginning of a prefix operator when it is defined. The `~` is not used when you use the operator, only when it is defined.
126135

127136
## Example
128137

0 commit comments

Comments
 (0)