Skip to content

Commit 090c434

Browse files
authored
Clarify that first pipe character is optional in discriminated union syntax (#48750)
1 parent e6f6b19 commit 090c434

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/fsharp/language-reference/discriminated-unions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ type [accessibility-modifier] type-name =
1818
[ member-list ]
1919
```
2020

21+
The first pipe character (`|`) is optional. For single-case discriminated unions, you can omit it:
22+
23+
```fsharp
24+
type SingleCase = Case of string
25+
```
26+
2127
## Remarks
2228

2329
Discriminated unions are similar to union types in other languages, but there are differences. As with a union type in C++ or a variant type in Visual Basic, the data stored in the value is not fixed; it can be one of several distinct options. Unlike unions in these other languages, however, each of the possible options is given a *case identifier*. The case identifiers are names for the various possible types of values that objects of this type could be; the values are optional. If values are not present, the case is equivalent to an enumeration case. If values are present, each value can either be a single value of a specified type, or a tuple that aggregates multiple fields of the same or different types. You can give an individual field a name, but the name is optional, even if other fields in the same case are named.

0 commit comments

Comments
 (0)