on master help sign in
Add info on $= record update syntax.
7da4cf2Bartosz
docs/tutorial/typesfuns.rst+4−3
@@ -1067,11 +1067,12 @@ updated):
1067
1067
1068 *record> record { firstName = "Jim" } fred
1068 *record> record { firstName = "Jim" } fred
1069 MkPerson "Jim" "Joe" "Bloggs" 30 : Person
1069 MkPerson "Jim" "Joe" "Bloggs" 30 : Person
1070− *record> record { firstName = "Jim", age = 20 } fred
1070+ *record> record { firstName = "Jim", age $= (+ 1) } fred
1071− MkPerson "Jim" "Joe" "Bloggs" 20 : Person
1071+ MkPerson "Jim" "Joe" "Bloggs" 31 : Person
1072
1072
1073The syntax ``record { field = val, ... }`` generates a function which
1073The syntax ``record { field = val, ... }`` generates a function which
1074−updates the given fields in a record.
1074+updates the given fields in a record. ``=`` assigns a new value to a field,
1075+and ``$=`` applies a function to update its value.
1075
1076
1076Each record is defined in its own namespace, which means that field names
1077Each record is defined in its own namespace, which means that field names
1077can be reused in multiple records.
1078can be reused in multiple records.