Module DA.Record¶
Exports the record machinery necessary to allow one to annotate code that is polymorphic in the underlying record type.
Typeclasses¶
class HasField x r a where
HasField
gives you getter and setter functions for each record field automatically.In the vast majority of use-cases, plain Record syntax should be preferred:
For more on Record syntax, see https://docs.daml.com/daml/intro/3_Data.html#record.
HasField x r a
is a typeclass that takes three parameters. The first parameterx
is the field name, the second parameterr
is the record type, and the last parametera
is the type of the field in this record. For example, if we define a type:Then we get, for free, the following HasField instances:
If we want to get a value using HasField, we can use the
getField
function:Note that this uses the “type application” syntax (
f @t
) to specify the field name.Likewise, if we want to set the value in the field, we can use the
setField
function:
- getField
- : r -> a
- setField
- : a -> r -> r