Prelude
Prelude
The pieces that make up the Daml language.
Typeclasses
class Action m => CanAssert m where
Constraint that determines whether an assertion can be made in this context.
assertFail: Text -> m t
Abort since an assertion has failed. In an Update, Scenario, or Script context this will throw an AssertionFailed exception. In an
Either Textcontext, this will return the message as an error.
class HasInterfaceTypeRep i where
(Daml-LF >= 1.15) Exposes the
interfaceTypeRepfunction. Available only for interfaces.
class HasToInterface t i where
(Daml-LF >= 1.15) Exposes the
toInterfaceandtoInterfaceContractIdfunctions.
class HasFromInterface t i where
(Daml-LF >= 1.15) Exposes
fromInterfacefromInterfaceandfromInterfaceContractIdfunctions.: i -> Optional t
(Daml-LF >= 1.15) Attempt to convert an interface value back into a template value. A
Noneindicates 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 where
_view: i -> v
class HasTime m where
The
getTimeHasTimeclass is for where the time is available:Update: HasCallStack => m Time
Get the current time.
class Action m => CanAbort m where
class Functor f => Applicative f where
pure: a -> f a
Lift a value.
(<*>): f (a -> b) -> f a -> f b
Sequentially apply the function.
A few functors support an implementation of
liftA2<*>that is more efficient than the default one.: (a -> b -> c) -> f a -> f b -> f c
Lift a binary function to actions.
Some functors support an implementation of
(*>)liftA2that 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 b
Sequence actions, discarding the value of the first argument.
(<*): f a -> f b -> f a
Sequence actions, discarding the value of the second argument.
instance Applicative ((->) r)
instance Applicative (State s)
instance Applicative Down
instance Applicative Update
instance Applicative Optional
instance Applicative Formula
instance Applicative NonEmpty
instance Applicative (Validation err)
instance Applicative (Either e)
instance Applicative ([])
class Applicative m => Action m where
class Action m => ActionFail m where
This class exists to desugar pattern matches in do-notation. Polymorphic usage, or calling
failfaildirectly, is not recommended. Instead consider usingCanAbort.: Text -> m a
Fail with an error message.
instance ActionFail Update
instance ActionFail Optional
instance ActionFail (Either Text)
instance ActionFail ([])
class Semigroup a where
The class of semigroups (types with an associative binary operation).
(<>): a -> a -> a
An associative operation.
instance Ord k => Semigroup (Map k v)
instance Semigroup (TextMap b)
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 [a]
class Semigroup a => Monoid a where
The class of monoids (types with an associative binary operation that has an identity).
mempty: a
Identity of
mconcat(<>): [a] -> a
Fold a list using the monoid. For example using
mconcaton a list of strings would concatenate all strings to one lone string.instance Ord k => Monoid (Map k v)
instance Multiplicative a => Monoid (Product a)
instance Additive a => Monoid (Sum a)
instance Ord k => Monoid (Set k)
instance Monoid [a]
class HasSignatory t where
class HasObserver t where
class HasEnsure t where
class HasCreate t where
Exposes
createcreatefunction. Part of theTemplateconstraint.: t -> Update (ContractId t)
Create a contract based on a template
t.
class HasFetch t where
Exposes
fetchfetchfunction. Part of theTemplateconstraint.: ContractId t -> Update t
Fetch the contract data associated with the given contract ID. If the
ContractId tsupplied is not the contract ID of an active contract, this fails and aborts the entire transaction.
class HasSoftFetch t where
Exposes
softFetchfunction
class HasSoftExercise t c r where
class HasArchive t where
Exposes
archivearchivefunction. Part of theTemplateconstraint.: ContractId t -> Update ()
Archive the contract with the given contract ID.
class HasTemplateTypeRep t where
Exposes
templateTypeRepfunction in Daml-LF 1.7 or later. Part of theTemplateconstraint.
class HasToAnyTemplate t where
Exposes
toAnyTemplatefunction in Daml-LF 1.7 or later. Part of theTemplateconstraint.
class HasFromAnyTemplate t where
Exposes
fromAnyTemplatefunction in Daml-LF 1.7 or later. Part of theTemplateconstraint.
class HasExercise t c r where
Exposes
exerciseexercisefunction. Part of theChoiceconstraint.: ContractId t -> c -> Update r
Exercise a choice on the contract with the given contract ID.
class HasChoiceController t c where
Exposes
choiceControllerfunction. Part of theChoiceconstraint.
class HasChoiceObserver t c where
Exposes
choiceObserverfunction. Part of theChoiceconstraint.
class HasExerciseGuarded t c r where
(1.dev only) Exposes
exerciseGuardedexerciseGuardedfunction. Only available for interface choices.: (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 returns
True.
class HasToAnyChoice t c r where
Exposes
toAnyChoicefunction for Daml-LF 1.7 or later. Part of theChoiceconstraint.
class HasFromAnyChoice t c r where
Exposes
fromAnyChoicefunction for Daml-LF 1.7 or later. Part of theChoiceconstraint.
class HasKey t k where
class HasLookupByKey t k where
Exposes
lookupByKeyfunction. Part of theTemplateKeyconstraint.
class HasFetchByKey t k where
Exposes
fetchByKeyfunction. Part of theTemplateKeyconstraint.
class HasLookupNByKey t k where
class HasMaintainer t k where
Exposes
maintainerfunction. Part of theTemplateKeyconstraint.
class HasExerciseByKey t k c r where
Exposes
exerciseByKeyfunction.
class IsParties a where
class Functor f where
A
fmapFunctoris a typeclass for things that can be mapped over (using itsfmapfunction. Examples includeOptional,[]andUpdate).: (a -> b) -> f a -> f b
fmaptakes a function of typea -> b, and turns it into a function of typef a -> f b, wherefis the type which is an instance ofFunctor.For example,
(<$)mapis anfmapthat only works on lists. It takes a functiona -> band a[a], and returns a[b].: a -> f b -> f a
Replace all locations in the input
f bwith the same valuea. The default definition isfmap . const, but you can override this with a more efficient version.
class Eq a where
The
Eqclass defines equality (==) and inequality (/=). All the basic datatypes exported by the "Prelude" are instances ofEq, andEqmay be derived for any datatype whose constituents are also instances ofEq.Usually,
==is expected to implement an equivalence relationship where two values comparing equal are indistinguishable by "public" functions, with a "public" function being one not allowing to see implementation details. For example, for a type representing non-normalised natural numbers modulo 100, a "public" function doesn’t make the difference between 1 and 201. It is expected to have the following properties:Reflexivity:
x == x=TrueSymmetry:
x == y=y == xTransitivity: if
x == y && y == z=True, thenx == z=TrueSubstitutivity: if
x == y=Trueandfis a "public" function whose return type is an instance ofEq, thenf x == f y=TrueNegation:
x /= y=not (x == y)Minimal complete definition: either
(==)==or/=.: a -> a -> Bool
(/=): a -> a -> Bool
instance (Eq a, Eq b) => Eq (Either a b)
instance Eq ()
instance (Eq a, Eq b) => Eq (a, b)
instance (Eq a, Eq b, Eq c) => Eq (a, b, c)
instance (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d)
instance (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
The
Ordclass is used for totally ordered datatypes.Instances of
Ordcan be derived for any user-defined datatype whose constituent types are inOrd. The declared order of the constructors in the data declaration determines the ordering in derivedOrdinstances. TheOrderingdatatype allows a single comparison to determine the precise ordering of two objects.The Haskell Report defines no laws for
Ord. However,<=is customarily expected to implement a non-strict partial order and have the following properties:Transitivity: if
x <= y && y <= z=True, thenx <= z=TrueReflexivity:
x <= x=TrueAntisymmetry: if
x <= y && y <= x=True, thenx == y=TrueNote that the following operator interactions are expected to hold:
x >= y=y <= x
x < y=x <= y && x /= y
x > y=y < x
x < y=compare x y == LT
x > y=compare x y == GT
x == y=compare x y == EQ
min x y == if x <= y then x else y= ‘True’
max x y == if x >= y then x else y= ‘True’Minimal complete definition: either
comparecompareor<=. Usingcomparecan be more efficient for complex types.: a -> a -> Ordering
(<): a -> a -> Bool
(<=): a -> a -> Bool
(>): a -> a -> Bool
(>=): a -> a -> Bool
max: a -> a -> a
min: a -> a -> a
instance (Ord a, Ord b) => Ord (Either a b)
instance Ord ()
instance (Ord a, Ord b) => Ord (a, b)
instance (Ord a, Ord b, Ord c) => Ord (a, b, c)
instance (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d)
instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord (a, b, c, d, e, f, g, h, i, j)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord (a, b, c, d, e, f, g, h, i, j, k)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord (a, b, c, d, e, f, g, h, i, j, k, l)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
class NumericScale n where
Is this a valid scale for the
Numerictype?This typeclass is used to prevent the creation of Numeric values with too large a scale. The scale controls the number of digits available after the decimal point, and it must be between 0 and 37 inclusive.
Thus the only available instances of this typeclass are
NumericScale 0throughNumericScale 37. This cannot be extended without additional compiler and runtime support. You cannot implement a custom instance of this typeclass.If you have an error message in your code of the form "No instance for
numericScale(NumericScale n)", this is probably caused by having a numeric literal whose scale cannot be inferred by the compiler. You can usually fix this by adding a type signature to the definition, or annotating the numeric literal directly (for example, instead of writing3.14159you can write(3.14159 : Numeric 5)).: Int
Get the scale of a
numericOneNumericas an integer. For example,numericScale (3.14159 : Numeric 5)equals5.: Numeric n
1 with scale n
instance NumericScale 0
instance NumericScale 1
instance NumericScale 10
instance NumericScale 11
instance NumericScale 12
instance NumericScale 13
instance NumericScale 14
instance NumericScale 15
instance NumericScale 16
instance NumericScale 17
instance NumericScale 18
instance NumericScale 19
instance NumericScale 2
instance NumericScale 20
instance NumericScale 21
instance NumericScale 22
instance NumericScale 23
instance NumericScale 24
instance NumericScale 25
instance NumericScale 26
instance NumericScale 27
instance NumericScale 28
instance NumericScale 29
instance NumericScale 3
instance NumericScale 30
instance NumericScale 31
instance NumericScale 32
instance NumericScale 33
instance NumericScale 34
instance NumericScale 35
instance NumericScale 36
instance NumericScale 37
instance NumericScale 4
instance NumericScale 5
instance NumericScale 6
instance NumericScale 7
instance NumericScale 8
instance NumericScale 9
class Bounded a where
Use the
Boundedclass to name the upper and lower limits of a type.You can derive an instance of the
Boundedclass for any enumeration type.minBoundis the first constructor listed in thedatadeclaration andmaxBoundis the last.You can also derive an instance of
Boundedfor single-constructor data types whose constituent types are inBounded.minBound
Ordis not a superclass ofBoundedbecause types that are not totally ordered can still have upper and lower bounds.: a
maxBound: a
class Enum a where
Use the
Enumclass to define operations on sequentially ordered types: that is, types that can be enumerated.Enummembers have defined successors and predecessors, which you can get with thesuccandpredfunctions.Types that are an instance of class
Boundedas well asEnumshould respect the following laws:
Both
succ maxBoundandpred minBoundshould result in a runtime error.
fromEnumandtoEnumshould give a runtime error if the result value is not representable in the result type. For example,toEnum 7 : Boolis an error.
enumFromandenumFromThenshould be defined with an implicit bound, like this:succenumFrom x = enumFromTo x maxBound enumFromThen x y = enumFromThenTo x y bound where bound | fromEnum y >= fromEnum x = maxBound | otherwise = minBound: a -> a
Returns the successor of the given value. For example, for numeric types,
succadds 1.If the type is also an instance of
predBounded,succ maxBoundresults in a runtime error.: a -> a
Returns the predecessor of the given value. For example, for numeric types,
predsubtracts 1.If the type is also an instance of
toEnumBounded,pred minBoundresults in a runtime error.: Int -> a
Convert a value from an
fromEnumIntto anEnumvalue: ie,toEnum ireturns the item at theith position of (the instance of)Enum: a -> Int
Convert a value from an
Enumvalue to anInt: ie, returns theIntposition of the element within theEnum.If
enumFromfromEnumis applied to a value that’s too large to fit in anInt, what is returned is up to your implementation.: a -> [a]
Return a list of the
Enumvalues starting at theIntposition. For example:enumFromThen
enumFrom 6 : [Int] = [6,7,8,9,...,maxBound : Int]: a -> a -> [a]
Returns a list of the
Enumvalues with the first value at the firstIntposition, the second value at the secondIntposition, and further values with the same distance between them.For example:
enumFromTo
enumFromThen 4 6 : [Int] = [4,6,8,10...]
enumFromThen 6 2 : [Int] = [6,2,-2,-6,...,minBound :: Int]: a -> a -> [a]
Returns a list of the
Enumvalues with the first value at the firstIntposition, and the last value at the lastIntposition.This is what’s behind the language feature that lets you write
[n,m..].For example:
enumFromThenTo
enumFromTo 6 10 : [Int] = [6,7,8,9,10]: a -> a -> a -> [a]
Returns a list of the
Enumvalues with the first value at the firstIntposition, the second value at the secondIntposition, and further values with the same distance between them, with the final value at the finalIntposition.This is what’s behind the language feature that lets you write
[n,n'..m].For example:
enumFromThenTo 4 2 -6 : [Int] = [4,2,0,-2,-4,-6]
enumFromThenTo 6 8 2 : [Int] = []
class Additive a where
Use the
Additiveclass for types that can be added. Instances have to respect the following laws:(+)
(+)must be associative, ie:(x + y) + z=x + (y + z)
(+)must be commutative, ie:x + y=y + x
x + aunit=x
negategives the additive inverse, ie:x + negate x=aunit: a -> a -> a
Add the two arguments together.
aunit: a
The additive identity for the type. For example, for numbers, this is 0.
(-): a -> a -> a
Subtract the second argument from the first argument, ie.
negatex - y=x + negate y: a -> a
Negate the argument:
x + negate x=aunitinstance NumericScale n => Additive (Numeric n)
class Multiplicative a where
Use the
Multiplicativeclass for types that can be multiplied. Instances have to respect the following laws:(*)
(*)is associative, ie:(x * y) * z=x * (y * z)
(*)is commutative, ie:x * y=y * x
x * munit=x: a -> a -> a
Multipy the arguments together
munit: a
The multiplicative identity for the type. For example, for numbers, this is 1.
(^): a -> Int -> a
x ^ nraisesxto the power ofn.instance Multiplicative Int
instance NumericScale n => Multiplicative (Numeric n)
class (Additive a, Multiplicative a) => Number a where
Numberis a class for numerical types. As well as the rules forAdditiveandMultiplicative, instances also have to respect the following law:
(*)is distributive with respect to(+). That is:a * (b + c)=(a * b) + (a * c)and(b + c) * a=(b * a) + (c * a)instance NumericScale n => Number (Numeric n)
class Signed a where
class Multiplicative a => Divisible a where
class Divisible a => Fractional a where
Use the
Fractionalclass for types that can be divided and where the reciprocal is well defined. Instances have to respect the following laws:recip
When
recip xis defined, it must be the inverse ofxwith respect to multiplication:x * recip x = munitWhen
recip yis defined, thenx / y = x * recip y: a -> a
Calculates the reciprocal:
recip xis1/x.instance NumericScale n => Fractional (Numeric n)
class Show a where
Use the
Showclass for values that can be converted to a readableTextvalue.Derived instances of
Showhave the following properties:showsPrec
The result of
showis a syntactically correct expression that only contains constants (given the fixity declarations in force at the point where the type is declared). It only contains the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used.If the constructor is defined to be an infix operator, then
showsPrecproduces infix applications of the constructor.If the precedence of the top-level constructor in
xis less thand(associativity is ignored), the representation will be enclosed in parentheses. For example, ifdis0then the result is never surrounded in parentheses; ifdis11it is always surrounded in parentheses, unless it is an atomic expression.If the constructor is defined using record syntax, then
showwill produce the record-syntax form, with the fields given in the same order as the original declaration.Convert a value to a readable
showTextvalue. Unlikeshow,showsPrecshould satisfy the ruleshowsPrec d x r ++ s == showsPrec d x (r ++ s): a -> Text
Convert a value to a readable
showListTextvalue.: [a] -> ShowS
Allows you to show lists of values.
instance (Show a, Show b) => Show (Either a b)
instance Show ()
instance (Show a, Show b) => Show (a, b)
instance (Show a, Show b, Show c) => Show (a, b, c)
instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d)
instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e)
Data Types
data AnyChoice
data AnyTemplate
Existential template type that can wrap an arbitrary template.
Field
Type
Description
getAnyTemplate
Any
instance Eq AnyTemplate
instance Ord AnyTemplate
data TemplateTypeRep
Unique textual representation of a template Id.
Field
Type
Description
getTemplateTypeRep
TypeRep
instance Eq TemplateTypeRep
instance Ord TemplateTypeRep
data Down a
type Implements t i
= (HasInterfaceTypeRep i, HasToInterface t i, HasFromInterface t i)
(Daml-LF >= 1.15) Constraint that indicates that a template implements an interface.
data AnyException
Warning
DEPRECATED:
Exceptions are deprecated, preferfailWithStatus, and avoid using catch.Use-Wno-deprecated-exceptionsto disable this warning.A wrapper for all exception types.
instance HasFromAnyException AnyException
instance HasMessage AnyException
instance HasToAnyException AnyException
data ContractId a
The
ContractId atype represents an ID for a contract created from a templatea. You can use the ID to fetch the contract, among other things.instance Serializable (ContractId a)
instance Eq (ContractId a)
instance Ord (ContractId a)
instance Show (ContractId a)
data Date
data Map a b
The
Map a btype represents an associative array from keys of typeato values of typeb. It uses the built-in equality for keys. ImportDA.Mapto use it.instance Ord k => Foldable (Map k)
instance Ord k => Monoid (Map k v)
instance Ord k => Semigroup (Map k v)
instance Ord k => Traversable (Map k)
instance (Serializable a, Serializable b) => Serializable (Map a b)
instance Ord k => Functor (Map k)
instance (Ord k, Eq v) => Eq (Map k v)
data Party
data TextMap a
data Time
data Update a
The
Update atype represents anActionto update or query the ledger, before returning a value of typea. Examples includecreateandfetch.instance ActionCatch Update
instance ActionThrow Update
instance ActionFailWithStatus Update
instance ActionFail Update
instance Applicative Update
data Optional a
The
Optionaltype encapsulates an optional value. A value of typeOptional aeither contains a value of typea(represented asSome a), or it is empty (represented asNone). UsingOptionalis a good way to deal with errors or exceptional cases without resorting to drastic measures such aserror.The
Optionaltype is also anAction. It is a simple kind of errorAction, where all errors are represented byNone. A richer errorActioncould be built using theData.Either.Eithertype.Some a
instance HasFromHex (Optional Party)
instance HasFromHex (Optional Int)
instance HasFromHex (Optional Text)
instance ActionFail Optional
instance Applicative Optional
instance IsParties (Optional Party)
instance Traversable Optional
instance Serializable a => Serializable (Optional a)
instance Eq a => Eq (Optional a)
data Archive
type Choice t c r
= (Template t, HasExercise t c r, HasToAnyChoice t c r, HasFromAnyChoice t c r)
Constraint satisfied by choices.
type Template t= (HasTemplateTypeRep t, HasToAnyTemplate t, HasFromAnyTemplate t)
type TemplateKey t k= (Template t, HasKey t k, HasFetchByKey t k, HasMaintainer t k)
Constraint satisfied by template keys.
data Either a b
type ShowSThe
Eithertype represents values with two possibilities: a value of typeEither a bis eitherLeft aorRight b.The
Eithertype is sometimes used to represent a value which is either correct or an error; by convention, theLeftconstructor is used to hold an error value and theRightconstructor is used to hold a correct value (mnemonic: "right" also means "correct").Left a
Right b
instance (Eq a, Eq b) => Eq (Either a b)
showS should represent some text, and applying it to some argument
should prepend the argument to the represented text.
data Bool
type Decimal
= Numeric 10
data Int
data Nat
(Kind) This is the kind of type-level naturals.
data Numeric n
A type for fixed-point decimal numbers, with the scale being passed as part of the type.
Numeric nrepresents a fixed-point decimal number with a fixed precision of 38 (i.e. 38 digits not including a leading zero) and a scale ofn, i.e.,ndigits after the decimal point.
nmust be between 0 and 37 (bounds inclusive).Examples:
0.01 : Numeric 2 0.0001 : Numeric 4instance NumericScale n => Additive (Numeric n)
instance NumericScale n => Divisible (Numeric n)
instance NumericScale n => Fractional (Numeric n)
instance NumericScale n => Multiplicative (Numeric n)
instance NumericScale n => Number (Numeric n)
instance NumericScale n => Signed (Numeric n)
data Ordering
data Text
data [] a
Functions
assertCheck whether a condition is true. If it’s not, abort the transaction.
assertMsg: CanAssert m => Text -> Bool -> m ()
Check whether a condition is true. If it’s not, abort the transaction with a message.
assertAfter: (CanAssert m, HasTime m) => Time -> m ()
Check whether the given time is in the future. If it’s not, abort the transaction.
assertBefore: (CanAssert m, HasTime m) => Time -> m ()
Check whether the given time is in the past. If it’s not, abort the transaction.
daysSinceEpochToDateConvert from number of days since epoch (i.e. the number of days since January 1, 1970) to a date.
dateToDaysSinceEpochConvert from a date to number of days from epoch (i.e. the number of days since January 1, 1970).
interfaceTypeRep: HasInterfaceTypeRep i => i -> TemplateTypeRep
(Daml-LF >= 1.15) Obtain the TemplateTypeRep for the template given in the interface value.
: HasToInterface t i => t -> i
(Daml-LF >= 1.15) Convert a template value into an interface value.
For example toInterface @MyInterface value converts a template
value into a MyInterface type.
: HasToInterface t i => ContractId t -> ContractId i
(Daml-LF >= 1.15) Convert a template contract id into an interface
contract id. For example, toInterfaceContractId @MyInterface cid.
: HasFromInterface t i => ContractId i -> ContractId t
(Daml-LF >= 1.15) Convert an interface contract id into a template
contract id. For example, 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.
: (HasInterfaceTypeRep i, HasInterfaceTypeRep j) => ContractId i -> ContractId j
(Daml-LF >= 1.15) Convert an interface contract id into a contract id of a
different interface. For example, given two interfaces 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.
: (HasFromInterface t i, HasFetch i) => ContractId i -> Update (Optional (ContractId t, t))
(Daml-LF >= 1.15) Fetch an interface and convert it to a specific
template type. If conversion is succesful, this function returns
the converted contract and its converted contract id. Otherwise,
this function returns 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:
do
fetchResult <- fetchFromInterface @MyTemplate ifaceCid
case fetchResult of
None -> abort "Failed to convert interface to appropriate template type"
Some (tplCid, tpl) -> do
... do something with tpl and tplCid ...
: a -> b -> c -> Bool
view: HasInterfaceView i v => i -> v
partyToTextConvert the 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.
Converts a 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:
∀ p. partyFromText (partyToText p) = Some p
∀ txt p. partyFromText txt = Some p ==> partyToText p = txt
This function will crash at runtime if you compile Daml to Daml-LF < 1.2.
coerceContractId: ContractId a -> ContractId b
Used to convert the type index of a 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.
: ((a, b) -> c) -> a -> b -> c
Turn a function that takes a pair into a function that takes two arguments.
uncurry: (a -> b -> c) -> (a, b) -> c
Turn a function that takes two arguments into a function that takes a pair.
(>>): Action m => m a -> m b -> m b
Sequentially compose two actions, discarding any value produced by the first. This is like sequencing operators (such as the semicolon) in imperative languages.
ap: Applicative f => f (a -> b) -> f a -> f b
Synonym for <*>.
: Applicative m => a -> m a
Inject a value into the monadic type. For example, for Update and a
value of type a, return would give you an Update a.
: Action m => m (m a) -> m a
Collapses nested actions into a single action.
identity: a -> a
The identity function.
guard: ActionFail m => Bool -> m ()
foldl: (b -> a -> b) -> b -> [a] -> b
This function is a left fold, which you can use to inspect/analyse/consume lists.
foldl f i xs performs a left fold over the list xs using
the function f, using the starting value i.
Examples:
>>> foldl (+) 0 [1,2,3]
6
>>> foldl (^) 10 [2,3]
1000000
Note that foldl works from left-to-right over the list arguments.
find: (a -> Bool) -> [a] -> Optional a
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.
: [a] -> Int
Gives the length of the list.
anyAre there any elements in the list where the predicate is true?
any p xs is True if p holds for at least one element of xs.
Is the predicate true for all of the elements in the list?
all p xs is True if p holds for every element of xs.
Is at least one of elements in a list of Bool true?
or bs is True if at least one element of bs is True.
Is every element in a list of Bool true?
and bs is True if every element of bs is True.
Does this value exist in this list?
elem x xs is True if x is an element of the list xs.
Negation of elem:
elem x xs is True if x is not an element of the list xs.
: Functor f => (a -> b) -> f a -> f b
Synonym for fmap.
: b -> (a -> b) -> Optional a -> b
The 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:
>>> optional False (> 2) (Some 3)
True
>>> optional False (> 2) None
False
>>> optional 0 (*2) (Some 5)
10
>>> optional 0 (*2) None
0
This example applies 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:
>>> optional "" show (Some 5)
"5"
>>> optional "" show (None : Optional Int)
""
: (a -> c) -> (b -> c) -> Either a b -> c
The 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):
>>> let s = Left [1,2,3] : Either [Int] Int in either length (*2) s
3
>>> let n = Right 3 : Either [Int] Int in either length (*2) n
6
: [[a]] -> [a]
Take a list of lists and concatenate those lists into one list.
(++): [a] -> [a] -> [a]
Concatenate two lists.
flip: (a -> b -> c) -> b -> a -> c
Flip the order of the arguments of a two argument function.
reverse: [a] -> [a]
Reverse a list.
mapA: Applicative m => (a -> m b) -> [a] -> m [b]
Apply an applicative function to each element of a list.
forA: Applicative m => [a] -> (a -> m b) -> m [b]
forA is mapA with its arguments flipped.
: Applicative m => [m a] -> m [a]
Perform a list of actions in sequence and collect the results.
(=<<): Action m => (a -> m b) -> m a -> m b
=<< is >>= with its arguments flipped.
: (a -> [b]) -> [a] -> [b]
Map a function over each element of a list, and concatenate all the results.
replicate: Int -> a -> [a]
replicate i x gives the list [x, x, x, ..., x] with i copies of x.
: Int -> [a] -> [a]
Take the first n elements of a list.
: Int -> [a] -> [a]
Drop the first n elements of a list.
: Int -> [a] -> ([a], [a])
Split a list at a given index.
takeWhile: (a -> Bool) -> [a] -> [a]
Take elements from a list while the predicate holds.
dropWhile: (a -> Bool) -> [a] -> [a]
Drop elements from a list while the predicate holds.
span: (a -> Bool) -> [a] -> ([a], [a])
span p xs is equivalent to (takeWhile p xs, dropWhile p xs).
: (a -> Bool) -> [a] -> ([a], [a])
The 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)
>>> partition (<0) [1, -2, -3, 4, -5, 6]
([-2, -3, -5], [1, 4, 6])
: (a -> Bool) -> [a] -> ([a], [a])
Break a list into two, just before the first element where the predicate holds.
break p xs is equivalent to span (not . p) xs.
: Eq a => a -> [(a, b)] -> Optional b
Look up the first element with a matching key.
enumerateGenerate a list containing all values of a given enumeration.
zip: [a] -> [b] -> [(a, b)]
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.
: [a] -> [b] -> [c] -> [(a, b, c)]
zip3 takes three lists and returns a list of triples, analogous to zip.
: (a -> b -> c) -> [a] -> [b] -> [c]
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.
: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3 generalises zip3 by combining elements using the function, instead of forming triples.
: [(a, b)] -> ([a], [b])
Turn a list of pairs into a pair of lists.
unzip3: [(a, b, c)] -> ([a], [b], [c])
Turn a list of triples into a triple of lists.
traceRaw: Text -> a -> a
traceRaw msg a prints msg and returns a, for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
trace: Show b => b -> a -> a
trace b a prints b and returns a, for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
traceId: Show b => b -> b
traceId a prints a and returns a, for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
debug: (Show b, Action m) => b -> m ()
debug x prints x for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
debugRawdebugRaw msg prints msg for debugging purposes.
The default configuration on the participant logs these messages at DEBUG level.
fst: (a, b) -> a
Return the first element of a tuple.
snd: (a, b) -> b
Return the second element of a tuple.
truncatetruncate x rounds x toward zero.
: NumericScale n => Int -> Numeric n
Convert an Int to a Numeric.
Convert an Int to a Decimal.
: Int -> Numeric n -> Numeric n
Bankers’ Rounding: roundBankers dp x rounds x to dp decimal places, where a .5 is rounded to the nearest even digit.
: NumericScale n => Int -> Numeric n -> Numeric n
Commercial Rounding: roundCommercial dp x rounds x to dp decimal places, where a .5 is rounded away from zero.
: NumericScale n => Numeric n -> Int
Round a Numeric to the nearest integer, where a .5 is rounded away from zero.
: NumericScale n => Numeric n -> Int
Round a Decimal down to the nearest integer.
: NumericScale n => Numeric n -> Int
Round a Decimal up to the nearest integer.
: [a] -> Bool
Is the list empty? null xs is true if xs is the empty list.
: (a -> Bool) -> [a] -> [a]
Filters the list using the function: keep only the elements where the predicate holds.
sum: Additive a => [a] -> a
Add together all the elements in the list.
product: Multiplicative a => [a] -> a
Multiply all the elements in the list together.
undefined: a
A convenience function that can be used to mark something not implemented. Always throws an error with "Not implemented."
softFetch: HasSoftFetch t => ContractId t -> Update t
softExercise: HasSoftExercise t c r => ContractId t -> c -> Update r
stakeholder: (HasSignatory t, HasObserver t) => t -> [Party]
The stakeholders of a contract: its signatories and observers.
maintainer: HasMaintainer t k => k -> [Party]
The list of maintainers of a contract key.
lookupByKey: (HasKey t k, HasLookupNByKey t k) => k -> Update (Optional (ContractId t))
Look up the contract ID t associated with a given contract key k (see
lookupNByKey for more on contract order).
You must pass the t using an explicit type application. For
instance, if you want to look up a contract of template Account by its
key k, you must call lookupByKey @Account k.
: HasFetchByKey t k => k -> Update (ContractId t, t)
Fetch the first contract ID and contract data associated with the given
contract key (see lookupNByKey for more on contract order).
You must pass the t using an explicit type application. For
instance, if you want to fetch a contract of template Account by its
key k, you must call fetchByKey @Account k.
: HasExerciseByKey t k c r => k -> c -> Update r
Exercise a choice on the first contract associated with the given key (see
lookupNByKey for more on contract order).
You must pass the 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.
: (HasCreate t, HasExercise t c r) => t -> c -> Update r
Create a contract and exercise the choice on the newly created contract.
templateTypeRep: HasTemplateTypeRep t => TemplateTypeRep
Generate a unique textual representation of the template id.
toAnyTemplate: HasToAnyTemplate t => t -> AnyTemplate
Wrap the template in AnyTemplate.
Only available for Daml-LF 1.7 or later.
fromAnyTemplate: HasFromAnyTemplate t => AnyTemplate -> Optional t
Extract the underlying template from AnyTemplate if the type matches
or return None.
Only available for Daml-LF 1.7 or later.
toAnyChoice: (HasTemplateTypeRep t, HasToAnyChoice t c r) => c -> AnyChoice
Wrap a choice in 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: (HasTemplateTypeRep t, HasFromAnyChoice t c r) => AnyChoice -> Optional c
Extract the underlying choice from 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.
visibleByKey: (HasKey t k, HasLookupNByKey t k) => k -> Update Bool
True if contract exists, submitter is a stakeholder, and all maintainers authorize. False if contract does not exist and all maintainers authorize. Fails otherwise.
otherwise: Bool
Used as an alternative in conditions.
map: (a -> b) -> [a] -> [b]
map f xs applies the function f to all elements of the list xs
and returns the list of results (in the same order as xs).
: (a -> b -> b) -> b -> [a] -> b
This function is a right fold, which you can use to manipulate lists.
foldr f i xs performs a right fold over the list xs using
the function f, using the starting value i.
Note that foldr works from right-to-left over the list elements.
(.): (b -> c) -> (a -> b) -> a -> c
Composes two functions, i.e., (f . g) x = f (g x).
: a -> b -> a
const x is a unary function which evaluates to x for all inputs.
>>> const 42 "hello"
42
>>> map (const 42) [0..3]
[42,42,42,42]
: (a -> b) -> a -> b
Take a function from a to b and a value of type a, and apply the
function to the value of type a, returning a value of type b.
This function has a very low precedence, which is why you might want to use
it instead of regular function application.
Boolean "and". This function has short-circuiting semantics, i.e., when both arguments are present and the first arguments evaluates to ‘False’, the second argument is not evaluated at all.
(||)Boolean "or". This function has short-circuiting semantics, i.e., when both arguments are present and the first arguments evaluates to ‘True’, the second argument is not evaluated at all.
notBoolean "not"
error: Text -> a
Throws a GeneralError exception.
: Additive a => a -> a -> a
subtract x y is equivalent to y - x.
This is useful for partial application, e.g., in subtract 1 since (- 1) is
interpreted as the number -1 and not a function that subtracts 1 from
its argument.
x % y calculates the remainder of x by y
Utility function that surrounds the inner show function with parentheses when the ‘Bool’ parameter is ‘True’.
showStringUtility function converting a ‘String’ to a show function that simply prepends the string unchanged.
showSpace: ShowS
Prepends a single space to the front of the string.
showCommaSpace: ShowS
Prepends a comma and a single space to the front of the string.