| Start |
|---|
| Basic Syntax Records are an extension of sum algebraic The field names can then be used to get the named field out of the record Records can be pattern matched against Notice that not all fields need be named Records are created by naming their fields, but can also be created as ordinary sum types (often useful when the number of fields is small and not likely to change) If a record is created without a named field, the compiler will issue a warning, and the resulting value will be A field of a record can be updated by setting its value. Unmentioned fields do not change. It is often useful to create lenses (opens new window) for complicated record types. |
| Defining a data type with field labels It is possible to define a data type with field labels. This definition differs from a normal record definition as it also defines *record accessors which can be used to access parts of a data type. In this example, two record accessors are defined, Record accessors are just Haskell functions which are automatically generated by the compiler. As such, they are used like ordinary Haskell functions. By naming fields, we can also use the field labels in a number of other contexts in order to make our code more readable. Pattern MatchingWe can bind the value located at the position of the relevant field label whilst pattern matching to a new value (in this case Pattern Matching with |
| Copying Records while Changing Field Values Suppose you have this type: and two values: a new value of type The values of |
| Records with newtype Record syntax can be used with It is important to note that the record syntax is typically never used to form values and the field name is used strictly for unwrapping |
Pattern Matching with RecordWildcards When matching using This extension is slightly controversial as it is not clear how values are brought into scope if you are not sure of the definition of Record UpdatesThere is also special syntax for updating data types with field labels. |
Read Article
https://develop.horje.com/learn/1434/reference