Documentation Index
Fetch the complete documentation index at: https://docs.canton.network/llms.txt
Use this file to discover all available pages before exploring further.
Prelude
The pieces that make up the Daml language.Module Snapshot
Lifecycle
Stable.
Notices
Status:
active
Introduced in: 3.4.9
Removed in: -
Warnings: 0
Deprecations: 0
Deprecated since: -Data Types
data AnyChoice
Existential choice type that can wrap an arbitrary choice.
Constructors:
AnyChoice| Field | Type | Description | | :---- | :--- | :---------- | | getAnyChoice | Any | | | getAnyChoiceTemplateTypeRep | TemplateTypeRep | |
instance Eq AnyChoiceinstance Ord AnyChoice
data AnyContractKey
Existential contract key type that can wrap an arbitrary contract key.
Constructors:
AnyContractKey| Field | Type | Description | | :---- | :--- | :---------- | | getAnyContractKey | Any | | | getAnyContractKeyTemplateTypeRep | TemplateTypeRep | |
instance Eq AnyContractKeyinstance Ord AnyContractKey
data AnyTemplate
Existential template type that can wrap an arbitrary template.
Constructors:
AnyTemplate| Field | Type | Description | | :---- | :--- | :---------- | | getAnyTemplate | Any | |
instance Eq AnyTemplateinstance Ord AnyTemplate
data TemplateTypeRep
Unique textual representation of a template Id.
Constructors:
TemplateTypeRep| Field | Type | Description | | :---- | :--- | :---------- | | getTemplateTypeRep | TypeRep | |
instance Eq TemplateTypeRepinstance Ord TemplateTypeRep
data Down a
The Down type can be used for reversing sorting order.
For example, sortOn (\x -> Down x.field) would sort by descending field.
Constructors:
Down a
instance Action Downinstance Applicative Downinstance Functor Downinstance Eq a => Eq (Down a)instance Ord a => Ord (Down a)instance Show a => Show (Down a)
type Implements = (HasInterfaceTypeRep i, HasToInterface t i, HasFromInterface t i)
(Daml-LF >= 1.15) Constraint that indicates that a template implements an interface.
data AnyException
A wrapper for all exception types.
Instances:
instance HasFromAnyException AnyExceptioninstance HasMessage AnyExceptioninstance HasToAnyException AnyException
data ContractId a
The ContractId a type represents an ID for a contract created from a template a.
You can use the ID to fetch the contract, among other things.
Instances:
instance Eq (ContractId a)instance Ord (ContractId a)instance Show (ContractId a)
data Date
The Date type represents a date, for example date 2007 Apr 5.
The bounds for Date are 0001-01-01 and 9999-12-31.
Instances:
instance Eq Dateinstance Ord Dateinstance Bounded Dateinstance Enum Dateinstance Show Date
data Map a b
The Map a b type represents an associative array from keys of type a
to values of type b. It uses the built-in equality for keys. Import
DA.Map to use it.
Instances:
instance Ord k => Foldable (Map k)instance Ord k => Monoid (Map k v)instance Ord k => Semigroup (Map k v)instance GetField map (Set k) (Map k ())instance SetField map (Set k) (Map k ())instance Ord k => Traversable (Map k)instance Ord k => Functor (Map k)instance (Ord k, Eq v) => Eq (Map k v)instance (Ord k, Ord v) => Ord (Map k v)instance (Show k, Show v) => Show (Map k v)
data Party
The Party type represents a party to a contract.
Instances:
instance HasFromHex (Optional Party)instance HasToHex Partyinstance IsParties Partyinstance IsParties (Optional Party)instance IsParties (NonEmpty Party)instance IsParties (Set Party)instance IsParties [Party]instance Eq Partyinstance Ord Partyinstance Show Party
data TextMap a
The TextMap a type represents an associative array from keys of type
Text to values of type a.
Instances:
instance Foldable TextMapinstance Monoid (TextMap b)instance Semigroup (TextMap b)instance GetField meta FailureStatus (TextMap Text)instance SetField meta FailureStatus (TextMap Text)instance Traversable TextMapinstance Functor TextMapinstance Eq a => Eq (TextMap a)instance Ord a => Ord (TextMap a)instance Show a => Show (TextMap a)
data Time
The Time type represents a specific datetime in UTC,
for example time (date 2007 Apr 5) 14 30 05.
The bounds for Time are 0001-01-01T00:00:00.000000Z and
9999-12-31T23:59:59.999999Z.
Instances:
instance Eq Timeinstance Ord Timeinstance Bounded Timeinstance Show Time
data Update a
The Update a type represents an Action to update or query the ledger,
before returning a value of type a. Examples include create and fetch.
Instances:
instance CanAssert Updateinstance ActionCatch Updateinstance ActionThrow Updateinstance ActionFailWithStatus Updateinstance CanAbort Updateinstance HasTime Updateinstance Action Updateinstance ActionFail Updateinstance Applicative Updateinstance Functor Update
data Optional a
The Optional type encapsulates an optional value. A value of type
Optional a either contains a value of type a (represented as Some a),
or it is empty (represented as None). Using Optional is a good way to
deal with errors or exceptional cases without resorting to drastic
measures such as error.
The Optional type is also an Action. It is a simple kind of error
Action, where all errors are represented by None. A richer
error Action could be built using the Data.Either.Either type.
Constructors:
None
Some a
instance HasFromHex (Optional Party)instance HasFromHex (Optional Int)instance HasFromHex (Optional Text)instance Foldable Optionalinstance Action Optionalinstance ActionFail Optionalinstance Applicative Optionalinstance IsParties (Optional Party)instance Traversable Optionalinstance Functor Optionalinstance Eq a => Eq (Optional a)instance Ord a => Ord (Optional a)instance Show a => Show (Optional a)
data Archive
The data type corresponding to the implicit Archive
choice in every template.
Constructors:
Archive(no fields)
instance Eq Archiveinstance Show Archive
type Choice = (Template t, HasExercise t c r, HasToAnyChoice t c r, HasFromAnyChoice t c r)
Constraint satisfied by choices.
type Template = (HasTemplateTypeRep t, HasToAnyTemplate t, HasFromAnyTemplate t)
type TemplateKey = (Template t, HasKey t k, HasLookupByKey t k, HasFetchByKey t k, HasMaintainer t k, HasToAnyContractKey t k, HasFromAnyContractKey t k)
Constraint satisfied by template keys.
Typeclasses
class Action m => CanAssert m
Constraint that determines whether an assertion can be made
in this context.
Methods:
assertFail : Text -> m tAbort since an assertion has failed. In an Update, Scenario, or Script context this will throw an AssertionFailed exception. In anEither Textcontext, this will return the message as an error.
instance CanAssert Updateinstance CanAssert (Either Text)
class HasInterfaceTypeRep i
(Daml-LF >= 1.15) Exposes the interfaceTypeRep function. Available only for interfaces.
class HasToInterface t i
(Daml-LF >= 1.15) Exposes the toInterface and toInterfaceContractId functions.
class HasFromInterface t i
(Daml-LF >= 1.15) Exposes fromInterface and fromInterfaceContractId
functions.
Methods:
-
fromInterface : i -> Optional t(Daml-LF >= 1.15) Attempt to convert an interface value back into a template value. ANoneindicates that the expected template type doesn’t match the underyling template type for the interface value. For example,fromInterface @MyTemplate valuewill try to convert the interface valuevalueinto the template typeMyTemplate.
class HasInterfaceView i v
Methods:
_view : i -> v
class HasTime m
The HasTime class is for where the time is available: Update
Methods:
getTime : HasCallStack => m TimeGet the current time.
instance HasTime Update
class Action m => CanAbort m
The CanAbort class is for Action s that can be aborted.
Methods:
abort : Text -> m aAbort the current action with a message.
instance CanAbort Updateinstance CanAbort (Either Text)
class Functor f => Applicative f
Methods:
-
pure : a -> f aLift a value. -
<*> : f (a -> b) -> f a -> f bSequentially apply the function. A few functors support an implementation of<*>that is more efficient than the default one. -
liftA2 : (a -> b -> c) -> f a -> f b -> f cLift a binary function to actions. Some functors support an implementation ofliftA2that is more efficient than the default one. In particular, iffmapis an expensive operation, it is likely better to useliftA2than tofmapover the structure and then use<*>. -
*> : f a -> f b -> f bSequence actions, discarding the value of the first argument. -
<* : f a -> f b -> f aSequence actions, discarding the value of the second argument.
instance Applicative (-> r)instance Applicative (State s)instance Applicative Downinstance Applicative Updateinstance Applicative Optionalinstance Applicative Formulainstance Applicative NonEmptyinstance Applicative (Validation err)instance Applicative (Either e)instance Applicative []
class Applicative m => Action m
Methods:
>>= : m a -> (a -> m b) -> m bSequentially compose two actions, passing any value produced by the first as an argument to the second.
instance Action (-> r)instance Action (State s)instance Action Downinstance Action Updateinstance Action Optionalinstance Action Formulainstance Action NonEmptyinstance Action (Either e)instance Action []
class Action m => ActionFail m
This class exists to desugar pattern matches in do-notation.
Polymorphic usage, or calling fail directly, is not recommended.
Instead consider using CanAbort.
Methods:
fail : Text -> m aFail with an error message.
instance ActionFail Updateinstance ActionFail Optionalinstance ActionFail (Either Text)instance ActionFail []
class Semigroup a
The class of semigroups (types with an associative binary operation).
Methods:
<> : a -> a -> aAn associative operation.
instance Ord k => Semigroup (Map k v)instance Semigroup (TextMap b)instance Semigroup Allinstance Semigroup Anyinstance Semigroup (Endo a)instance Multiplicative a => Semigroup (Product a)instance Additive a => Semigroup (Sum a)instance Semigroup (NonEmpty a)instance Ord a => Semigroup (Max a)instance Ord a => Semigroup (Min a)instance Ord k => Semigroup (Set k)instance Semigroup (Validation err a)instance Semigroup Orderinginstance Semigroup Textinstance Semigroup [a]
class Semigroup a => Monoid a
The class of monoids (types with an associative binary operation that has an identity).
Methods:
mempty : aIdentity of(<>)mconcat : [a] -> aFold a list using the monoid. For example usingmconcaton a list of strings would concatenate all strings to one lone string.
instance Ord k => Monoid (Map k v)instance Monoid (TextMap b)instance Monoid Allinstance Monoid Anyinstance Monoid (Endo a)instance Multiplicative a => Monoid (Product a)instance Additive a => Monoid (Sum a)instance Ord k => Monoid (Set k)instance Monoid Orderinginstance Monoid Textinstance Monoid [a]
class HasSignatory t
Exposes signatory function. Part of the Template constraint.
Methods:
signatory : t -> [Party]The signatories of a contract.
class HasObserver t
Exposes observer function. Part of the Template constraint.
Methods:
observer : t -> [Party]The observers of a contract.
class HasEnsure t
Exposes ensure function. Part of the Template constraint.
Methods:
ensure : t -> BoolA predicate that must be true, otherwise contract creation will fail.
class HasCreate t
Exposes create function. Part of the Template constraint.
Methods:
create : t -> Update (ContractId t)Create a contract based on a templatet.
class HasFetch t
Exposes fetch function. Part of the Template constraint.
Methods:
fetch : ContractId t -> Update tFetch the contract data associated with the given contract ID. If theContractId tsupplied is not the contract ID of an active contract, this fails and aborts the entire transaction.
class HasSoftFetch t
Exposes softFetch function
class HasSoftExercise t c r
class HasArchive t
Exposes archive function. Part of the Template constraint.
Methods:
archive : ContractId t -> Update ()Archive the contract with the given contract ID.
class HasTemplateTypeRep t
Exposes templateTypeRep function in Daml-LF 1.7 or later.
Part of the Template constraint.
class HasToAnyTemplate t
Exposes toAnyTemplate function in Daml-LF 1.7 or later.
Part of the Template constraint.
class HasFromAnyTemplate t
Exposes fromAnyTemplate function in Daml-LF 1.7 or later.
Part of the Template constraint.
class HasExercise t c r
Exposes exercise function. Part of the Choice constraint.
Methods:
exercise : ContractId t -> c -> Update rExercise a choice on the contract with the given contract ID.
class HasChoiceController t c
Exposes choiceController function. Part of the Choice constraint.
class HasChoiceObserver t c
Exposes choiceObserver function. Part of the Choice constraint.
class HasExerciseGuarded t c r
(1.dev only) Exposes exerciseGuarded function.
Only available for interface choices.
Methods:
exerciseGuarded : (t -> Bool) -> ContractId t -> c -> Update r(1.dev only) Exercise a choice on the contract with the given contract ID, only if the predicate returnsTrue.
class HasToAnyChoice t c r
Exposes toAnyChoice function for Daml-LF 1.7 or later.
Part of the Choice constraint.
class HasFromAnyChoice t c r
Exposes fromAnyChoice function for Daml-LF 1.7 or later.
Part of the Choice constraint.
class HasKey t k
Exposes key function. Part of the TemplateKey constraint.
Methods:
key : t -> kThe key of a contract.
class HasLookupByKey t k
Exposes lookupByKey function. Part of the TemplateKey constraint.
Methods:
-
lookupByKey : k -> Update (Optional (ContractId t))Look up the contract IDtassociated with a given contract keyk. You must pass thetusing an explicit type application. For instance, if you want to look up a contract of templateAccountby its keyk, you must calllookupByKey @Account k.
class HasFetchByKey t k
Exposes fetchByKey function. Part of the TemplateKey constraint.
Methods:
-
fetchByKey : k -> Update (ContractId t, t)Fetch the contract ID and contract data associated with a given contract key. You must pass thetusing an explicit type application. For instance, if you want to fetch a contract of templateAccountby its keyk, you must callfetchByKey @Account k.
class HasMaintainer t k
Exposes maintainer function. Part of the TemplateKey constraint.
class HasToAnyContractKey t k
Exposes toAnyContractKey function in Daml-LF 1.7 or later.
Part of the TemplateKey constraint.
class HasFromAnyContractKey t k
Exposes fromAnyContractKey function in Daml-LF 1.7 or later.
Part of the TemplateKey constraint.
class HasExerciseByKey t k c r
Exposes exerciseByKey function.
class IsParties a
Accepted ways to specify a list of parties: either a single party, or a list of parties.
Methods:
toParties : a -> [Party]Convert to list of parties.
instance IsParties Partyinstance IsParties (Optional Party)instance IsParties (NonEmpty Party)instance IsParties (Set Party)instance IsParties [Party]
Functions
assert
assertMsg
assertAfter
assertBefore
daysSinceEpochToDate
dateToDaysSinceEpoch
interfaceTypeRep
TemplateTypeRep for the template given in the interface value.
toInterface
toInterface @MyInterface value converts a template
value into a MyInterface type.
toInterfaceContractId
toInterfaceContractId @MyInterface cid.
fromInterfaceContractId
fromInterfaceContractId @MyTemplate cid.
Can also be used to convert an interface contract id into a contract id of
one of its requiring interfaces.
This function does not verify that the interface contract id
actually points to a template of the given type. This means
that a subsequent fetch, exercise, or archive may fail, if,
for example, the contract id points to a contract that implements
the interface but is of a different template type than expected.
Therefore, you should only use fromInterfaceContractId in situations
where you already know that the contract id points to a contract of the
right template type. You can also use it in situations where you will
fetch, exercise, or archive the contract right away, when a transaction
failure is the appropriate response to the contract having the wrong
template type.
In all other cases, consider using fetchFromInterface instead.
coerceInterfaceContractId
Source and Target,
and cid : ContractId Source,
coerceInterfaceContractId @Target @Source cid : ContractId Target.
This function does not verify that the contract id
actually points to a contract that implements either interface. This means
that a subsequent fetch, exercise, or archive may fail, if,
for example, the contract id points to a contract of template A but it was
coerced into a ContractId B where B is an interface and there’s no
interface instance B for A.
Therefore, you should only use coerceInterfaceContractId in situations
where you already know that the contract id points to a contract of the right
type. You can also use it in situations where you will fetch, exercise, or
archive the contract right away, when a transaction failure is the
appropriate response to the contract having the wrong type.
fetchFromInterface
None.
Can also be used to fetch and convert an interface contract id into a
contract and contract id of one of its requiring interfaces.
Example:
_exerciseInterfaceGuard
view
partyToText
Party to Text, giving back what you passed to getParty.
In most cases, you should use show instead. show wraps
the party in 'ticks' making it clear it was a Party originally.
partyFromText
Text to Party. It returns None if the provided text contains
any forbidden characters. See Daml-LF spec for a specification on which characters
are allowed in parties. Note that this function accepts text without
single quotes.
This function does not check on whether the provided
text corresponds to a party that “exists” on a given ledger: it merely converts
the given Text to a Party. The only way to guarantee that a given Party
exists on a given ledger is to involve it in a contract.
This function, together with partyToText, forms an isomorphism between
valid party strings and parties. In other words, the following equations hold:
coerceContractId
ContractId, since they are just
pointers. Note that subsequent fetches and exercises might fail if the
template of the contract on the ledger doesn’t match.
curry
uncurry
>>
ap
<*>.
return
Update and a
value of type a, return would give you an Update a.
join
identity
guard
foldl
foldl f i xs performs a left fold over the list xs using
the function f, using the starting value i.
Examples:
find
find p xs finds the first element of the list xs where the
predicate p is true. There might not be such an element, which
is why this function returns an Optional a.
length
any
any p xs is True if p holds for at least one element of xs.
all
all p xs is True if p holds for every element of xs.
or
Bool true?
or bs is True if at least one element of bs is True.
and
and bs is True if every element of bs is True.
elem
elem x xs is True if x is an element of the list xs.
notElem
elem:
elem x xs is True if x is not an element of the list xs.
<$>
fmap.
optional
optional function takes a default value, a function, and a Optional
value. If the Optional value is None, the function returns the
default value. Otherwise, it applies the function to the value inside
the Some and returns the result.
Basic usage examples:
show to a Optional Int. If you have Some n,
this shows the underlying Int, n. But if you have None, this
returns the empty string instead of (for example) None:
either
either function provides case analysis for the Either type.
If the value is Left a, it applies the first function to a;
if it is Right b, it applies the second function to b.
Examples:
This example has two values of type Either [Int] Int, one using the
Left constructor and another using the Right constructor. Then
it applies either the length function (if it has a [Int])
or the “times-two” function (if it has an Int):
concat
++
flip
reverse
mapA
forA
forA is mapA with its arguments flipped.
sequence
=<<
=<< is >>= with its arguments flipped.
concatMap
replicate
replicate i x gives the list [x, x, x, ..., x] with i copies of x.
take
n elements of a list.
drop
n elements of a list.
splitAt
takeWhile
dropWhile
span
span p xs is equivalent to (takeWhile p xs, dropWhile p xs).
partition
partition function takes a predicate, a list and returns
the pair of lists of elements which do and do not satisfy the
predicate, respectively; i.e.,
partition p xs == (filter p xs, filter (not . p) xs)
break
break p xs is equivalent to span (not . p) xs.
lookup
enumerate
zip
zip takes two lists and returns a list of corresponding pairs.
If one list is shorter, the excess elements of the longer list are discarded.
zip3
zip3 takes three lists and returns a list of triples, analogous to zip.
zipWith
zipWith takes a function and two lists.
It generalises zip by combining elements using the function, instead of forming pairs.
If one list is shorter, the excess elements of the longer list are discarded.
zipWith3
zipWith3 generalises zip3 by combining elements using the function, instead of forming triples.
unzip
unzip3
traceRaw
traceRaw msg a prints msg and returns a, for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
trace
trace b a prints b and returns a, for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
traceId
traceId a prints a and returns a, for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
debug
debug x prints x for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
debugRaw
debugRaw msg prints msg for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
fst
snd
truncate
truncate x rounds x toward zero.
intToNumeric
Int to a Numeric.
intToDecimal
Int to a Decimal.
roundBankers
roundBankers dp x rounds x to dp decimal places, where a .5 is rounded to the nearest even digit.
roundCommercial
roundCommercial dp x rounds x to dp decimal places, where a .5 is rounded away from zero.
round
Numeric to the nearest integer, where a .5 is rounded away from zero.
floor
Decimal down to the nearest integer.
ceiling
Decimal up to the nearest integer.
null
null xs is true if xs is the empty list.
filter
sum
product
undefined
softFetch
softExercise
stakeholder
maintainer
exerciseByKey
t using an explicit type application. For
instance, if you want to exercise a choice Withdraw on a contract of
template Account given by its key k, you must call
exerciseByKey @Account k Withdraw.
createAndExercise
templateTypeRep
toAnyTemplate
AnyTemplate.
Only available for Daml-LF 1.7 or later.
fromAnyTemplate
AnyTemplate if the type matches
or return None.
Only available for Daml-LF 1.7 or later.
toAnyChoice
AnyChoice.
You must pass the template type t using an explicit type application.
For example toAnyChoice @Account Withdraw.
Only available for Daml-LF 1.7 or later.
fromAnyChoice
AnyChoice if the template and
choice types match, or return None.
You must pass the template type t using an explicit type application.
For example fromAnyChoice @Account choice.
Only available for Daml-LF 1.7 or later.
toAnyContractKey
AnyContractKey.
You must pass the template type t using an explicit type application.
For example toAnyContractKey @Proposal k.
Only available for Daml-LF 1.7 or later.
fromAnyContractKey
AnyContractKey if the template and
choice types match, or return None.
You must pass the template type t using an explicit type application.
For example fromAnyContractKey @Proposal k.
Only available for Daml-LF 1.7 or later.
visibleByKey
Orphan Typeclass Instances
-
instance Eq a => Eq (Down a) -
instance Show a => Show (Down a) -
instance Functor Down -
instance Functor a -
instance Functor [] -
instance Functor (-> r) -
instance Functor (Either e) -
instance Ord a => Ord (Down a) -
instance Ord TemplateTypeRep -
instance Eq Archive -
instance Show Archive -
instance Eq AnyTemplate -
instance Eq AnyChoice -
instance Eq AnyContractKey -
instance Ord AnyTemplate -
instance Ord AnyChoice -
instance Ord AnyContractKey -
instance Eq TemplateTypeRep