Skip to content

Commit 312d84a

Browse files
authored
(doc) mention record update syntax (#1909)
1 parent 6cc2a57 commit 312d84a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

data/tutorials/language/0it_01_basic_datatypes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,14 @@ val ghorghor_bey : character =
705705
- : int = 17
706706
```
707707

708+
To construct a new record with some field values changed without typing in the unchanged fields we can use record update syntax as shown:
709+
```ocaml
710+
# let togrev = { ghorghor_bey with name = "Togrev"; level = 20; armor_class = -6 };;
711+
val togrev : character =
712+
{name = "Togrev"; level = 20; race = "half-ogre"; class_type = Fighter;
713+
alignment = (Chaotic, R_Neutral); armor_class = -6}
714+
```
715+
708716
Note that records behave like single constructor variants. That allows pattern matching on them.
709717
```ocaml
710718
# match ghorghor_bey with { level; _ } -> level;;

0 commit comments

Comments
 (0)