Skip to content

Commit 03758f0

Browse files
committed
Add section on empty variants in basic data types tutorial
1 parent 2a3ea11 commit 03758f0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

data/tutorials/language/0it_01_basic_datatypes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,16 @@ Note that:
482482
- `unit` is a variant with a unique constructor, which does not carry data: `()`.
483483
- `bool` is also a variant with two constructors that doesn't carry data: `true` and `false`.
484484

485+
#### Empty Variants
486+
487+
Variants can optionally be defined with absolutely no constructors at all.
488+
489+
```ocaml
490+
type void = |
491+
```
492+
493+
Such types are not ordinarily useful in OCaml programs (as they do not have any constructible values), but they can be useful as temporary placeholders when defining types in a [functor](/docs/functors#writing-your-own-functors).
494+
485495
#### Constructors With Data
486496

487497
It is possible to wrap data in constructors. The following type has several constructors with data (e.g., `Hash of string`) and some without (e.g., `Head`). It represents the different means to refer to a Git [revision](https://git-scm.com/docs/gitrevisions).

0 commit comments

Comments
 (0)