- Overview
- Tutorials
- Getting started
- Get started with Canton and the JSON Ledger API
- Get Started with Canton, the JSON Ledger API, TypeScript and WebSockets
- Get Started with Canton, the JSON Ledger API, and TypeScript
- Multi-Synchronizer Operations with the JSON Ledger API and TypeScript
- Get started with Canton Network App Dev Quickstart
- Using the JSON Ledger API
- Deploy Quickstart to DevNet
- Appendix
- Get started with smart contract development
- Basic contracts
- Test templates using Daml scripts
- Build the Daml Archive (.dar) file
- Data types
- Transform contracts using choices
- Add constraints to a contract
- Parties and authority
- Compose choices
- Handle exceptions (Deprecated)
- Work with dependencies
- Functional programming 101
- The Daml standard library
- Test Daml contracts
- Next steps
- Interfaces
- Application development
- Getting started
- Development how-tos
- Best practices for Canton Network application development
- System design
- Application development
- How to use the Canton Network App Dev Quickstart
- Develop
- How to upload and query Daml packages
- How to allocate and query Daml parties
- Multi-Synchronizer Application Best Practices
- How to Onboard and Use External Parties in Quickstart
- How to work with contracts and transactions in Java
- How to disclose contracts to non-stakeholders
- How to query contracts and transactions using SQL
- Debug
- Observe
- Secure
- Harden
- Optimize
- Upgrade
- Smart contract development
- Migration guides
- Component how-tos
- Explanations
- References
- Application development
- Smart contract development
- Daml language cheat sheet
- Daml language reference
- Overview: Template Structure
- Reference: Templates
- Reference: Choices
- Reference: Updates
- Reference: Data Types
- Reference: Built-in Functions
- Reference: Expressions
- Reference: Functions
- Reference: Daml File Structure
- Reference: Daml Packages
- Reference: Contract Keys
- Reference: Interfaces
- Reference: Exceptions (Deprecated)
- Reference: Serializable
- Fixity, Associativity and Precedence
- Daml standard library
- DA.Action.State.Class
- DA.Action.State
- DA.Action
- DA.Assert
- DA.Bifunctor
- DA.Crypto.Text
- DA.Date
- DA.Either
- DA.Exception
- DA.Fail
- DA.Foldable
- DA.Functor
- DA.Internal.Interface.AnyView.Types
- DA.Internal.Interface.AnyView
- DA.List.BuiltinOrder
- DA.List.Total
- DA.List
- DA.Logic
- DA.Map
- DA.Math
- DA.Monoid
- DA.NonEmpty.Types
- DA.NonEmpty
- DA.Numeric
- DA.Optional
- DA.Record
- DA.Semigroup
- DA.Set
- DA.Stack
- DA.Text
- DA.TextMap
- DA.Time
- DA.Traversable
- DA.Tuple
- DA.Validation
- DA.ContractKeys
- GHC.Show.Text
- GHC.Tuple.Check
- Prelude
- Daml Script
- Smart contract upgrading reference
- Glossary of concepts
DA.Record¶
Exports the record machinery necessary to allow one to annotate code that is polymorphic in the underlying record type.
Typeclasses¶
class GetField x r a where
GetField x r aprovides the getter part ofHasField
- getField
: r -> a
class SetField x r a where
SetField x r aprovides the setter part ofHasField
- setField
: a -> r -> r
Data Types¶
- type HasField x r a
= (GetField x r a, SetField x r a)
HasFieldis a class synonym forGetFieldandSetField, which respectively give you getter and setter functions for each record field automatically.In the vast majority of use-cases, plain Record syntax should be preferred:
daml> let a = MyRecord 1 "hello" daml> a.foo 1 daml> a.bar "hello" daml> a { bar = "bye" } MyRecord {foo = 1, bar = "bye"} daml> a with foo = 3 MyRecord {foo = 3, bar = "hello"} daml>
For more on Record syntax, see https://docs.digitalasset.com/build/3.4/reference/daml/stdlib/DA-Record.html.
GetField x r aandSetField x r aare typeclasses taking three parameters. The first parameterxis the field name, the second parameterris the record type, and the last parameterais the type of the field in this record. For example, if we define a type:data MyRecord = MyRecord with foo : Int bar : Text
Then we get, for free, the following GetField and SetField instances:
GetField "foo" MyRecord Int SetField "foo" MyRecord Int GetField "bar" MyRecord Text SetField "bar" MyRecord Text
If we want to get a value, we can use the
getFieldmethod of classGetField:getFoo : MyRecord -> Int getFoo r = getField @"foo" r getBar : MyRecord -> Text getBar r = getField @"bar" r
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
setFieldmethod of classSetField:setFoo : Int -> MyRecord -> MyRecord setFoo a r = setField @"foo" a r setBar : Text -> MyRecord -> MyRecord setBar a r = setField @"bar" a r