- Overview
- Tutorials
- Getting started
- Get started with Canton and the JSON Ledger API
- Get Started with Canton, the JSON Ledger API, and TypeScript
- Get started with Canton Network App Dev Quickstart
- 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
- Work with dependencies
- Functional programming 101
- The Daml standard library
- Test Daml contracts
- Next steps
- Application development
- Getting started
- Development how-tos
- Component how-tos
- Explanations
- References
- Application development
- Smart contract development
- Daml language cheat sheet
- Daml language reference
- 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
- GHC.Show.Text
- GHC.Tuple.Check
- Prelude
- Smart contract upgrading reference
- Glossary of concepts
DA.Set¶
Note: This is only supported in Daml-LF 1.11 or later.
This module exports the generic set type Set k
and associated
functions. This module should be imported qualified, for example:
import DA.Set (Set)
import DA.Set qualified as S
This will give access to the Set
type, and the various operations
as S.lookup
, S.insert
, S.fromList
, etc.
Set k
internally uses the built-in order for the type k
.
This means that keys that contain functions are not comparable
and will result in runtime errors. To prevent this, the Ord k
instance is required for most set operations. It is recommended to
only use Set k
for key types that have an Ord k
instance
that is derived automatically using deriving
:
data K = ...
deriving (Eq, Ord)
This includes all built-in types that aren’t function types, such as
Int
, Text
, Bool
, (a, b)
assuming a
and b
have default
Ord
instances, Optional t
and [t]
assuming t
has a
default Ord
instance, Map k v
assuming k
and v
have
default Ord
instances, and Set k
assuming k
has a
default Ord
instance.
Data Types¶
data Set k
Functions¶
- notMember
-
Is the element not in the set?
notMember k s
is equivalent tonot (member k s)
.
- insert
: Ord k => k -> Set k -> Set k
Insert an element in a set. If the set already contains the element, this returns the set unchanged.
- intersection
: Ord k => Set k -> Set k -> Set k
The intersection of two sets.
- difference
: Ord k => Set k -> Set k -> Set k
difference x y
returns the set consisting of all elements inx
that are not iny
.> > > fromList [1, 2, 3] difference fromList [1, 4] > > > fromList [2, 3]
- isSubsetOf
: Ord k => Set k -> Set k -> Bool
isSubsetOf a b
returns true ifa
is a subset ofb
, that is, if every element ofa
is inb
.
- isProperSubsetOf
: Ord k => Set k -> Set k -> Bool
isProperSubsetOf a b
returns true ifa
is a proper subset ofb
. That is, ifa
is a subset ofb
but not equal tob
.