# Base for DAML 1.2¶

The base domain of the DAML standard library contains various modules with common definitions and helper functions.

## Module Prelude¶

### Typeclasses¶

**class Functor f where**

fmap- : (a -> b) -> f a -> f b

(<$): a -> f b -> f a

Replace all locations in the input with the same value. The default definition is

`fmap . const`

, but this may be overridden with a more efficient version.

**class Bounded a where**The

`Bounded`

class is used to name the upper and lower limits of a type.`Ord`

is not a superclass of`Bounded`

since types that are not totally ordered may also have upper and lower bounds.The

`Bounded`

class may be derived for any enumeration type;`minBound`

is the first constructor listed in the`data`

declaration and`maxBound`

is the last.`Bounded`

may also be derived for single-constructor datatypes whose constituent types are in`Bounded`

.**minBound**- : a

**maxBound**- : a

**class Enum a where**Class

`Enum`

defines operations on sequentially ordered types.The

`enumFrom`

… methods are used in Haskell’s translation of arithmetic sequences.Instances of

`Enum`

may be derived for any enumeration type (types whose constructors have no fields). The nullary constructors are assumed to be numbered left-to-right by`fromEnum`

from`0`

through`n-1`

. See Chapter 10 of the /Haskell Report/ for more details.For any type that is an instance of class

`Bounded`

as well as`Enum`

, the following should hold:- The calls
`succ`

`maxBound`

and`pred`

`minBound`

should result in a runtime error. `fromEnum`

and`toEnum`

should give a runtime error if the result value is not representable in the result type. For example,`toEnum`

7 :: Bool` is an error.`enumFrom`

and`enumFromThen`

should be defined with an implicit bound, thus:

enumFrom x = enumFromTo x maxBound enumFromThen x y = enumFromThenTo x y bound where bound | fromEnum y >= fromEnum x = maxBound | otherwise = minBound

**succ**: a -> a

the successor of a value. For numeric types, ‘succ’ adds 1.

**pred**: a -> a

the predecessor of a value. For numeric types, ‘pred’ subtracts 1.

**toEnum**: Int -> a

Convert from an ‘Int’.

**enumFrom**: a -> [a]

Used in Haskell’s translation of

`[n..]`

with`[n..] = enumFrom n`

, a possible implementation being`enumFrom n = n : enumFrom (succ n)`

. For example:`enumFrom 4 :: [Integer] = [4,5,6,7,...]`

`enumFrom 6 :: [Int] = [6,7,8,9,...,maxBound :: Int]`

**enumFromThen**: a -> a -> [a]

Used in Haskell’s translation of

`[n,n'..]`

with`[n,n'..] = enumFromThen n n'`

, a possible implementation being`enumFromThen n n' = n : n' : worker (f x) (f x n')`

,`worker s v = v : worker s (s v)`

,`x = fromEnum n' - fromEnum n`

and`f n y | n > 0 = f (n - 1) (succ y) | n < 0 = f (n + 1) (pred y) | otherwise = y`

For example:`enumFromThen 4 6 :: [Integer] = [4,6,8,10...]`

`enumFromThen 6 2 :: [Int] = [6,2,-2,-6,...,minBound :: Int]`

**enumFromTo**: a -> a -> [a]

Used in Haskell’s translation of

`[n..m]`

with`[n..m] = enumFromTo n m`

, a possible implementation being`enumFromTo n m | n <= m = n : enumFromTo (succ n) m | otherwise = []`

. For example:`enumFromTo 6 10 :: [Int] = [6,7,8,9,10]`

`enumFromTo 42 1 :: [Integer] = []`

**enumFromThenTo**: a -> a -> a -> [a]

Used in Haskell’s translation of

`[n,n'..m]`

with`[n,n'..m] = enumFromThenTo n n' m`

, a possible implementation being`enumFromThenTo n n' m = worker (f x) (c x) n m`

,`x = fromEnum n' - fromEnum n`

,`c x = bool (>=) (<=) (x > 0)`

`f n y | n > 0 = f (n - 1) (succ y) | n < 0 = f (n + 1) (pred y) | otherwise = y`

and`worker s c v m | c v m = v : worker s c (s v) m | otherwise = []`

For example:`enumFromThenTo 4 2 -6 :: [Integer] = [4,2,0,-2,-4,-6]`

`enumFromThenTo 6 8 2 :: [Int] = []`

- The calls

**class Additive a where**Basic additive class. Instances are expected to respect the following laws:

**Associativity of (+)**:`(x + y) + z`

=`x + (y + z)`

**Commutativity of (+)**:`x + y`

=`y + x`

`x + aunit`

=`x`

`negate`

**gives the additive inverse**:`x + negate x`

= aunit**(+)**- : a -> a -> a

**(-)**- : a -> a -> a

**negate**- : a -> a

**aunit**- : a

**class Multiplicative a where**Basic multiplicative class. Instances are expected to respect the following laws:

**Associativity of (*)**:`(x * y) * z`

=`x * (y * z)`

**Commutativity of (*)**:`x * y`

=`y * x`

`x * one`

=`x`

**(*)**- : a -> a -> a

**munit**- : a

**class (Additive a, Multiplicative a) => Number a where**Basic numeric class. Instances are usually expected to respect the following law (in addition to laws from being additive and multiplicative)

**Distributivity of (*) with respect to (+)**:`a * (b + c)`

=`(a * b) + (a * c)`

and`(b + c) * a`

=`(b * a) + (c * a)`

**class Signed a where**

signum- : a -> a

abs: a -> a

Absolute value.

**class Show a where**Conversion of values to readable ‘String’s.

Derived instances of ‘Show’ have the following properties, which are compatible with derived instances of ‘Text.Read.Read’:

- The result of ‘show’ is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only 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 ‘showsPrec’ will produce infix applications of the constructor.
- the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
`x`

is less than`d`

(associativity is ignored). Thus, if`d`

is`0`

then the result is never surrounded in parentheses; if`d`

is`11`

it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then ‘show’ will produce the record-syntax form, with the fields given in the same order as the original declaration.

For example, given the declarations

infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a

the derived instance of ‘Show’ is equivalent to

instance (Show a) => Show (Tree a) where showsPrec d (Leaf m) = showParen (d > app_prec) $ showString "Leaf " . showsPrec (app_prec+1) m where app_prec = 10 showsPrec d (u :^: v) = showParen (d > up_prec) $ showsPrec (up_prec+1) u . showString " :^: " . showsPrec (up_prec+1) v where up_prec = 5

Note that right-associativity of

`:^:`

is ignored. For example,`show (Leaf 1 :^: Leaf 2 :^: Leaf 3)`

produces the string`"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"`

.

**showsPrec**: Int -> a -> ShowS

Convert a value to a readable

`String`

.`showsPrec`

should satisfy the lawshowsPrec d x r ++ s == showsPrec d x (r ++ s)

Derived instances of ‘Text.Read.Read’ and ‘Show’ satisfy the following:

`(x,"")`

is an element of`(Text.Read.readsPrec d (showsPrec d x ""))`

.

That is,

`Text.Read.readsPrec`

parses the string produced by`showsPrec`

, and delivers the value that`showsPrec`

started with.

**show**: a -> Text

A specialised variant of ‘showsPrec’, using precedence context zero, and returning an ordinary ‘String’.

**showList**: [a] -> ShowS

The method ‘showList’ is provided to allow the programmer to give a specialised way of showing lists of values. For example, this is used by the predefined ‘Show’ instance of the ‘Char’ type, where values of type ‘String’ should be shown in double quotes, rather than between square brackets.

**class HasTime m where**Places where the time is available - basically

`Scenario`

and`Update`

.**getTime**: m Time

Obtain the current time.

**class (Action m) => CanAbort m where**

abort: Text -> m a

Abort the current action with a message.

**class (Multiplicative a) => Fractional a where**

(/): a -> a -> a

`x / y`

divides`x`

by`y`

.

recip: a -> a

Calculate the reciprocal:

`recip x`

is`1/x`

.

**class (Functor f) => Applicative f where**

pure: a -> f a

Lift a value.

(<*>): f (a -> b) -> f a -> f b

Sequential application.

A few functors support an implementation of ‘<*>’ that is more efficient than the default one.

liftA2: (a -> b -> c) -> f a -> f b -> f c

Lift a binary function to actions.

Some functors support an implementation of ‘liftA2’ that is more efficient than the default one. In particular, if ‘fmap’ is an expensive operation, it is likely better to use ‘liftA2’ than to ‘fmap’ over 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.

**class (Applicative m) => Action m where**

(>>=): m a -> (a -> m b) -> m b

Sequentially compose two actions, passing any value produced by the first as an argument to the second.

**class (Action m) => ActionFail m where**

fail: Text -> m a

Fail with an error message.

**class Semigroup a where**The class of semigroups (types with an associative binary operation).

**(<>)**: a -> a -> a

An associative operation.

**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

`mconcat`

on a list of strings would concatenate all strings to one lone string.

**class Template c where**

ensure: c -> Bool

Predicate that must hold for the succesful creation of the contract.

signatory: c -> [Party]

The signatories of a contract.

observer: c -> [Party]

The observers of a contract.

agreement: c -> Text

The agreement text of a contract.

**class (Template c) => Choice c e r where**

choiceController- : c -> e -> [Party]

choice- : c -> ContractId c -> e -> Update r

**class IsParties a where**Accepted ways to specify a list of parties: either a single party, or a list of parties.

**toParties**: a -> [Party]

Convert to list of parties.

### Data Types¶

- type
**ShowS** - = Text -> Text
The

`shows`

functions return a function that prepends the output ‘String’ to an existing ‘String’. This allows constant-time concatenation of results using function composition.

data **[] a**

Documentation for lists

[]

:a [a]

data **Bool**

False

True

data **Constraint**

The kind of constraints, like`Show a`

data **Decimal**

data **Int**

A 64-bit integer.

data **Ordering**

Information about ordering

LT

EQ

GT

data **Symbol**

(Kind) This is the kind of type-level symbols. Declared here because class IP needs it

data **Text**

data **ContractId a**

The

`ContractId a`

type represents an id for a contract made from template`a`

. The id can be used to fetch the contract, among other things.

ContractIdOpaque

data **Date**

The

`Date`

type represents a date.

DateOpaque

data **Party**

The

`Party`

type represents a party to a contract.

PartyOpaque

data **Scenario a**

The

`Scenario`

type is used to simulate multi-party ledger interactions. The type`Scenario a`

describes a set of actions taken by various parties during the simulated scenario, before returning a value of type`a`

.

ScenarioOpaque

data **Time**

The

`Time`

type represents a specific datetime in UTC, i.e. a date and a time in UTC.

TimeOpaque

data **Update a**

The

`Update a`

type represents an action to update or query the ledger, before returning a value of type`a`

.

UpdateOpaque

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`

.

Downa

data **Either a b**

The

`Either`

type represents values with two possibilities: a value of type`Either a b`

is either`Left a`

or`Right b`

.The

`Either`

type is sometimes used to represent a value which is either correct or an error; by convention, the`Left`

constructor is used to hold an error value and the`Right`

constructor is used to hold a correct value (mnemonic: “right” also means “correct”).

Lefta

Rightb

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 a monad. It is a simple kind of error monad, where all errors are represented by`None`

. A richer error monad can be built using the`Data.Either.Either`

type.

None

Somea

data **TextMap a**

The type of a`TextMap`

from keys of type Text to values of type`v`

.

data **Archive**

Archive

data **ChoiceType**

Consuming

NonConsuming

### Functions¶

**otherwise**- : Bool

**getTag**- : a -> Int#

**(++)**- : Text -> Text -> Text

**map**- : (a -> b) -> [a] -> [b]

**foldr**- : (a -> b -> b) -> b -> [a] -> b

**(.)**: (b -> c) -> (a -> b) -> a -> c

Function composition.

**const**: 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]

**eftInt**- : Int -> Int -> [Int]

**efdInt**- : Int -> Int -> [Int]

**efdtInt**- : Int -> Int -> Int -> [Int]

**efdtIntUp**- : Int -> Int -> Int -> [Int]

**go_up**- : Int -> Int -> Int -> [Int]

**efdtIntDn**- : Int -> Int -> Int -> [Int]

**go_dn**- : Int -> Int -> Int -> [Int]

**error**- : Text -> a

**showList__**- : (a -> ShowS) -> [a] -> ShowS

**showl**- : (a -> ShowS) -> [a] -> ShowS

**showParen**: Bool -> ShowS -> ShowS

utility function that surrounds the inner show function with parentheses when the ‘Bool’ parameter is ‘True’.

**showString**: Text -> ShowS

utility function converting a ‘String’ to a show function that simply prepends the string unchanged.

**showSpace**- : ShowS

**showCommaSpace**- : ShowS

**assert**: (CanAbort m) => Bool -> m ()

Check whether a condition is true, and otherwise abort.

**assertMsg**: (CanAbort m) => Text -> Bool -> m ()

Check whether a condition is true, and otherwise abort with a message.

**assertAfter**: (CanAbort m, HasTime m) => Time -> m ()

Check whether the given time is in the future, and otherwise abort.

**assertBefore**: (CanAbort m, HasTime m) => Time -> m ()

Check whether the given time is in the past, and otherwise abort.

**daysSinceEpochToDate**: Int -> Date

Convert number of days since epoc (i.e. the number of days since January 1, 1970) to a date.

**dateToDaysSinceEpoch**: Date -> Int

Convert a date to number of days epoch (i.e. the number of days since January 1, 1970).

**partyToText**: Party -> Text

Convert the

`Party`

to`Text`

, giving back what you passed to`getParty`

. Most users should stick to`show`

of the party instead, which also wraps the party in`'ticks'`

making it clear it was a`Party`

originally.

**partyFromText**: Text -> Optional Party

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.Also note that this function does not perform any check on whether the provided text correspond 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 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.

**getParty**: Text -> Scenario Party

Get the party with the given name. Party names must be non-empty and only contain alphanumeric charaters, space,

`-`

(dash) or`_`

(underscore).

**submit**: Party -> Update a -> Scenario a

`submit p u`

describes the scenario in which party`p`

attempts to update the ledger with update action`u`

, and returns the value returned by the underlying update action. This scenario is considered a failure if the underlying update action fails.

**submitMustFail**: Party -> Update a -> Scenario ()

`submitMustFail`

describes the scenario in which party`p`

attempts to update the ledger with update action`u`

, but is expected to fail. This scenario is considered a failure if the underlying update action succeeds.

**scenario**: Scenario a -> Scenario a

Declare you are building a scenario.

**($)**- : (a -> b) -> a -> b

**curry**: ((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.

**(^)**: Int -> Int -> Int

`x ^ n`

raises`x`

to the power of`n`

.

**(%)**: Int -> Int -> Int

`x % y`

calculates the remainder of`x`

by`y`

**(>>)**: (Applicative m) => m a -> m b -> m b

Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.

**ap**: (Applicative f) => f (a -> b) -> f a -> f b

Synonym for

`<*>`

.

**return**: (Applicative m) => a -> m a

Inject a value into the monadic type.

**join**: (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

`foldl f i xs`

performs a left fold over`xs`

using`f`

with the starting value`i`

.Examples——–

>>> foldl (+) 0 [1,2,3] 6 >>> foldl (^) 10 [2,3] 1000000

**find**: (a -> Bool) -> [a] -> Optional a

`find p xs`

finds the first element of`xs`

where the predicate`p`

holds.

**length**: [a] -> Int

Calculate the length of a list.

**any**: (a -> Bool) -> [a] -> Bool

`any p xs`

is`True`

if`p`

holds for at least one element of`xs`

.

**all**: (a -> Bool) -> [a] -> Bool

`all p xs`

is`True`

if`p`

holds for every element of`xs`

.

**or**: [Bool] -> Bool

`or bs`

is`True`

if at least one element of`bs`

is`True`

.

**and**: [Bool] -> Bool

`and bs`

is`True`

if every element of`bs`

is`True`

.

**elem**: (Eq a) => a -> [a] -> Bool

`elem x xs`

is`True`

if`x`

is an element of the list`xs`

.

**notElem**: (Eq a) => a -> [a] -> Bool

Negation of

`elem`

.

**(<$>)**: (Functor f) => (a -> b) -> f a -> f b

Synonym for

`fmap`

.

**optional**: 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.Examples——–

Basic usage:

>>> optional False odd (Some 3) True

>>> optional False odd None False

Read an Int from a string using

`readOptional`

. If we succeed, return twice the Int; that is, apply`(*2)`

to it. If instead we fail to parse an Int, return`0`

by default:>>> import Text.Read ( readOptional ) >>> optional 0 (*2) (readOptional "5") 10 >>> optional 0 (*2) (readOptional "") 0

Apply

`show`

to a`Optional Int`

. If we have`Some n`

, we want to show the underlying`Int`

,`n`

. But if we have`None`

, we return the empty string instead of (for example)`None`

:>>> optional "" show (Some 5) "5" >>> optional "" show None ""

**either**: (a -> c) -> (b -> c) -> Either a b -> c

Case analysis for the

`Either`

type. If the value is`Left a`

, apply the first function to`a`

; if it is`Right b`

, apply the second function to`b`

.Examples——–

We create two values of type

`Either String Int`

, one using the`Left`

constructor and another using the`Right`

constructor. Then we apply “either” the`length`

function (if we have a`String`

) or the “times-two” function (if we have an`Int`

):>>> let s = Left "foo" :: Either String Int >>> let n = Right 3 :: Either String Int >>> either length (*2) s 3 >>> either length (*2) n 6

**concat**- : [[a]] -> [a]

**(++)**: [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.

**sequence**: (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.

**concatMap**: (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`

is the list`[x, x, x, ..., x]`

with`i`

copies of`x`

.

**take**: Int -> [a] -> [a]

Take the first

`n`

elements of a list.

**drop**: Int -> [a] -> [a]

Drop the first

`n`

elements of a list.

**splitAt**: 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)`

.

**break**: (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`

.

**lookup**: (Eq a) => a -> [(a, b)] -> Optional b

Look up the first element with a matching key.

**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.

**zip3**: [a] -> [b] -> [c] -> [(a, b, c)]

`zip3`

takes three lists and returns a list of triples, analogous to`zip`

.

**zipWith**: (a -> b -> c) -> [a] -> [b] -> [c]

`zipWith`

generalises`zip`

by combining elements using the function, instead of making pairs. If one list is shorter, the excess elements of the longer list are discarded.

**zipWith3**: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]

`zipWith3`

generalises`zip3`

by combining elements using the function, instead of making pairs.

**unzip**: [(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.

**trace**: (Show b) => b -> a -> a

`trace b a`

prints`b`

and returns`a`

, for debugging purposes.

**traceId**: (Show b) => b -> b

`traceId a`

prints`a`

and returns`a`

, for debugging purposes.

**debug**: (Show b, Applicative m) => b -> m ()

`debug x`

prints`x`

for debugging purposes.

**fst**: (a, b) -> a

Return the first element of a pair.

**snd**: (a, b) -> b

Return the second element of a pair.

**truncate**: Decimal -> Int

`truncate x`

rounds`x`

toward zero.

**intToDecimal**: Int -> Decimal

Convert an

`Int`

to a`Decimal`

.

**roundBankers**: Int -> Decimal -> Decimal

Bankers’ Rounding:

`roundBankers dp x`

rounds`x`

to`dp`

decimal places, where a`.5`

is rounded to the nearest even digit.

**roundCommercial**: Int -> Decimal -> Decimal

Commercial Rounding:

`roundCommercial dp x`

rounds`x`

to`dp`

decimal places, where a`.5`

is rounded away from zero.

**round**: Decimal -> Int

Round to nearest integer, where a

`.5`

is rounded away from zero.

**floor**: Decimal -> Int

Round down to nearest integer.

**ceiling**: Decimal -> Int

Round up to nearest integer.

**null**: [a] -> Bool

`null xs`

is true if`xs`

is the empty list.

**filter**: (a -> Bool) -> [a] -> [a]

Keep only the elements where the predicate holds.

**sum**: (Additive a) => [a] -> a

Calculate the sum over all elements

**product**: (Multiplicative a) => [a] -> a

Calculate the product over all elements

**create**: (Template c) => c -> Update (ContractId c)

Create a contract based on a template.

**exercise**: ContractId c -> e -> Update r

Exercise a contract choice.

**fetch**: (Template c) => ContractId c -> Update c

Fetch the contract data associated with the given contract id. This fails and aborts the entire transaction if the

`ContractId c`

supplied is not the contract ID of an active contract.

**archive**: (Template c) => ContractId c -> Update ()

Archive the contract.

**stakeholder**: (Template c) => c -> [Party]

The stakeholders of a contract, i.e. its signatories and observers.

## Module Control.Exception.Base¶

### Functions¶

**recSelError**- : Text -> r

**absentSumFieldError**- : a

**untangle**- : Text -> Text -> Text

**append**- : Text -> Text -> Text

**break**- : (a -> Bool) -> [a] -> ([a], [a])

## Module DA.Action¶

Action

### Functions¶

**when**: (Applicative f) => Bool -> f () -> f ()

Conditional execution of

`Action`

expressions. For example,when final (archive contractId)

will archive the contract

`contractId`

if the Boolean value`final`

is`True`

, and otherwise do nothing.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.

**unless**: (Applicative f) => Bool -> f () -> f ()

The reverse of

`when`

.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.

**foldrA**: (Action m) => (a -> b -> m b) -> b -> [a] -> m b

The

`foldrA`

is analogous to`foldr`

, except that its result is encapsulated in an action. Note that`foldrA`

works from right-to-left over the list arguments.

**foldr1A**: (Action m) => (a -> a -> m a) -> [a] -> m a

`foldr1A`

is like`foldrA`

but raises an error when presented with an empty list argument.

**foldlA**: (Action m) => (b -> a -> m b) -> b -> [a] -> m b

`foldlA`

is analogous to`foldl`

, except that its result is encapsulated in an action. Note that`foldlA`

works from left-to-right over the list arguments.

**foldl1A**: (Action m) => (a -> a -> m a) -> [a] -> m a

The

`foldl1A`

is like`foldlA`

but raises an errors when presented with an empty list argument.

**replicateA**: (Applicative m) => Int -> m a -> m [a]

`replicateA n act`

performs the action`n`

times, gathering the results.

## Module DA.Assert¶

Assert

### Functions¶

**(===)**: (CanAbort m, Show a, Eq a) => a -> a -> m ()

Check two values for equivalence and fail with a message if they are not.

**assertAfterMsg**: (CanAbort m, HasTime m) => Text -> Time -> m ()

Check whether the given time is in the future, and otherwise abort with a message.

**assertBeforeMsg**: (CanAbort m, HasTime m) => Text -> Time -> m ()

Check whether the given time is in the past, and otherwise abort with a message.

## Module DA.Bifunctor¶

### Typeclasses¶

**class Bifunctor p where**A bifunctor is a type constructor that takes two type arguments and is a functor in /both/ arguments. That is, unlike with ‘Functor’, a type constructor such as ‘Either’ does not need to be partially applied for a ‘Bifunctor’ instance, and the methods in this class permit mapping functions over the ‘Left’ value or the ‘Right’ value, or both at the same time.

Intuitively it is a bifunctor where both the first and second arguments are covariant.

You can define a ‘Bifunctor’ by either defining ‘bimap’ or by defining both ‘first’ and ‘second’.

If you supply ‘bimap’, you should ensure that:

@’bimap’ ‘id’ ‘id’ ≡ ‘id’@

If you supply ‘first’ and ‘second’, ensure:

@ ‘first’ ‘id’ ≡ ‘id’ ‘second’ ‘id’ ≡ ‘id’ @

If you supply both, you should also ensure:

@’bimap’ f g ≡ ‘first’ f ‘.’ ‘second’ g@

These ensure by parametricity:

@ ‘bimap’ (f ‘.’ g) (h ‘.’ i) ≡ ‘bimap’ f h ‘.’ ‘bimap’ g i ‘first’ (f ‘.’ g) ≡ ‘first’ f ‘.’ ‘first’ g ‘second’ (f ‘.’ g) ≡ ‘second’ f ‘.’ ‘second’ g @

@since 4.8.0.0

**bimap**: (a -> b) -> (c -> d) -> p a c -> p b d

Map over both arguments at the same time.

@’bimap’ f g ≡ ‘first’ f ‘.’ ‘second’ g@

====

**Examples**> > > bimap toUpper (+1) (‘j’, 3) > > > (‘J’,4)

> > > bimap toUpper (+1) (Left ‘j’) > > > Left ‘J’

> > > bimap toUpper (+1) (Right 3) > > > Right 4

**first**: (a -> b) -> p a c -> p b c

Map covariantly over the first argument.

@’first’ f ≡ ‘bimap’ f ‘id’@

====

**Examples**> > > first toUpper (‘j’, 3) > > > (‘J’,3)

> > > first toUpper (Left ‘j’) > > > Left ‘J’

**second**: (b -> c) -> p a b -> p a c

Map covariantly over the second argument.

@’second’ ≡ ‘bimap’ ‘id’@

====

**Examples**> > > second (+1) (‘j’, 3) > > > (‘j’,4)

> > > second (+1) (Right 3) > > > Right 4

## Module DA.Date¶

### Data Types¶

data **DayOfWeek**

The

`DayOfWeek`

type represents one the seven days of the week.

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday

Sunday

data **Month**

The

`Month`

type represents a month in the Gregorian calendar.

Jan

Feb

Mar

Apr

May

Jun

Jul

Aug

Sep

Oct

Nov

Dec

### Functions¶

**addDays**: Date -> Int -> Date

Adjusts a date with given number of days.

**subDate**: Date -> Date -> Int

Returns number of days between two given dates.

**dayOfWeek**: Date -> DayOfWeek

Returns the day of week for given date

**fromGregorian**: (Int, Month, Int) -> Date

Constructs a

`Date`

from the triplet`(year, month, days)`

.

**toGregorian**: Date -> (Int, Month, Int)

Turn

`Date`

value into (year, month, day) triple, according to Gregorian calendar.

**date**: Int -> Month -> Int -> Date

`date (y, m, d)`

turns given year`y`

, month`m`

, and day`d`

into a`Date`

value.

**isLeapYear**: Int -> Bool

Calculate whethe the given year is a leap year.

**fromMonth**: Month -> Int

Get the number corresponding to given month. For example,

`Jan`

corresponds to`1`

,`Feb`

corresponds to`2`

, and so on.

**monthDayCount**: Int -> Month -> Int

Get number of days in month on given year, according to Gregorian calendar. This does not take historical calendar changes into account (for example, the moves from Julian to Gregorian calendar), but does count leap years.

**datetime**: Int -> Month -> Int -> Int -> Int -> Int -> Time

Constructs an instant using

`year`

,`month`

,`day`

,`hours`

,`minutes`

,`seconds`

.

**toDateUTC**: Time -> Date

Extracts UTC Date from UTC Time This function will truncate Time to Date, but in many cases it will not return the date you really want. The reason for this is that usually the source of Time would be getTime, and getTime returns UTC, and most likely the date you want is something local to a location or an exchange. Consequently the date retrieved this way would be yesterday if retrieved when the market opens in say Singapore.

**passToDate**: Date -> Scenario Time

Pass simulated scenario to given date.

## Module DA.Either¶

The Either type represents values with two possibilities.

It is sometimes used to represent a value which is either correct or an error; by convention the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: “right” also means correct).

### Functions¶

**lefts**: [Either a b] -> [a]

Extracts all the

`Left`

elements.

**rights**: [Either a b] -> [b]

Extracts all the

`Right`

elements.

**partitionEithers**: [Either a b] -> ([a], [b])

Partitions a list of

`Either`

into two lists, the`Left`

and`Right`

elements respectively. Order is maintained.

**isLeft**: Either a b -> Bool

Return

`True`

if the given value is a`Left`

-value,`False`

otherwise.

**isRight**: Either a b -> Bool

Return

`True`

if the given value is a`Right`

-value,`False`

otherwise.

**fromLeft**: a -> Either a b -> a

Return the contents of a

`Left`

-value or a default value otherwise.

**fromRight**: b -> Either a b -> b

Return the contents of a

`Right`

-value or a default value otherwise.

**optionalToEither**: a -> Optional b -> Either a b

Convert a

`Optional`

value to an`Either`

value, using the supplied parameter as the`Left`

value if the`Optional`

is`None`

.

**eitherToOptional**: Either a b -> Optional b

Convert an

`Either`

value to a`Optional`

, dropping any value in`Left`

.

**maybeToEither**- : a -> Optional b -> Either a b

**eitherToMaybe**- : Either a b -> Optional b

## Module DA.Foldable¶

Class of data structures that can be folded to a summary value.
You typically would want to import this module qualified to avoid clashes with
functions defined in Prelude. Ie.:
```
`
import DA.Foldable qualified as F
`
```

### Typeclasses¶

**class Foldable t where**Class of data structures that can be folded to a summary value.

**fold**: (Monoid m) => t m -> m

Combine the elements of a structure using a monoid.

**foldMap**: (Monoid m) => (a -> m) -> t a -> m

Combine the elements of a structure using a monoid.

**foldr**: (a -> b -> b) -> b -> t a -> b

Right-associative fold of a structure.

**foldl**: (b -> a -> b) -> b -> t a -> b

Left-associative fold of a structure.

**foldr1**: (a -> a -> a) -> t a -> a

A variant of foldr that has no base case, and thus should only be applied to non-empty structures.

**foldl1**: (a -> a -> a) -> t a -> a

A variant of foldl that has no base case, and thus should only be applied to non-empty structures.

**toList**: t a -> [a]

List of elements of a structure, from left to right.

**null**: t a -> Bool

Test whether the structure is empty. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.

**length**: t a -> Int

Returns the size/length of a finite structure as an

`Int`

. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.

**elem**: (Eq a) => a -> t a -> Bool

Does the element occur in the structure?

**sum**: (Additive a) => t a -> a

The sum function computes the sum of the numbers of a structure.

**product**: (Multiplicative a) => t a -> a

The product function computes the product of the numbers of a structure.

**minimum**: (Ord a) => t a -> a

The least element of a non-empty structure.

**maximum**: (Ord a) => t a -> a

The largest element of a non-empty structure.

### Functions¶

**concat**: (Foldable t) => t [a] -> [a]

The concatenation of all the elements of a container of lists.

**and**: (Foldable t) => t Bool -> Bool

`and`

returns the conjunction of a container of Bools. For the result to be`True`

, the container must be finite;`False`

, however, results from a`False`

value finitely far from the left end.

**or**: (Foldable t) => t Bool -> Bool

`or`

returns the disjunction of a container of Bools. For the result to be`False`

, the container must be finite;`True`

, however, results from a`True`

value finitely far from the left end.

**any**: (Foldable t) => (a -> Bool) -> t a -> Bool

Determines whether any element of the structure satisfies the predicate.

**all**: (Foldable t) => (a -> Bool) -> t a -> Bool

Determines whether all elements of the structure satisfy the predicate.

## Module DA.Functor¶

The Functor class is used for types that can be mapped over.

### Functions¶

**($>)**: (Functor f) => f a -> b -> f b

Replace all locations in the input (on the left) with the given value (on the right).

**(<&>)**: (Functor f) => f a -> (a -> b) -> f b

Map a function over a functor. Given a value

`as`

and a function`f`

,`as <&> f`

is`f <$> as`

. That is,`<&>`

is like`<$>`

but the arguments are in reverse order.

**void**: (Functor f) => f a -> f ()

Replace all the locations in the input with

`()`

.

## Module DA.Internal.Compatible¶

Our Prelude, extending WiredIn with things that don’t need special treatment.

### Data Types¶

- type
**Datetime** - = Time

- type
**Integer** - = Int

- type
**List a** - = [a]

- type
**Maybe** - = Optional

- type
**Monad** - = Action

- type
**MonadFail** - = ActionFail

- type
**Num** - = Number

- type
**Tuple a b** - = (a, b)

- type
**Tuple3 a b c** - = (a, b, c)

### Functions¶

**tuple**- : a -> b -> (a, b)

**tuple3**- : a -> b -> c -> (a, b, c)

**nil**- : [a]

**cons**- : a -> [a] -> [a]

**does**- : Party -> Update a -> Update a

**toText**- : (Show a) => a -> Text

**toInteger**- : Decimal -> Int

**mapU**- : (Applicative m) => (a -> m b) -> [a] -> m [b]

**forU**- : (Applicative m) => [a] -> (a -> m b) -> m [b]

**mapM**- : (Applicative m) => (a -> m b) -> [a] -> m [b]

**forM**- : (Applicative m) => [a] -> (a -> m b) -> m [b]

**commits**- : Party -> Update a -> Scenario a

**fails**- : Party -> Update a -> Scenario ()

**test**- : Scenario a -> Scenario a

**maybe**- : b -> (a -> b) -> Maybe a -> b

**id**- : a -> a

## Module DA.Internal.Desugar¶

Automatically imported qualified in every module.

## Module DA.Internal.RebindableSyntax¶

Automatically imported unqualified in every module.

## Module DA.Internal.Record¶

## Module DA.List¶

List

### Functions¶

**sort**: (Ord a) => [a] -> [a]

The

`sort`

function implements a stable sorting algorithm. It is a special case of`sortBy`

, which allows the programmer to supply their own comparison function.Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input (a stable sort).

**sortBy**: (a -> a -> Ordering) -> [a] -> [a]

The

`sortBy`

function is the non-overloaded version of`sort`

.

**sortOn**: (Ord k) => (a -> k) -> [a] -> [a]

Sort a list by comparing the results of a key function applied to each element.

`sortOn f`

is equivalent to`sortBy (comparing f)`

, but has the performance advantage of only evaluating`f`

once for each element in the input list. This is sometimes called the decorate-sort-undecorate paradigm.Elements are arranged from from lowest to highest, keeping duplicates in the order they appeared in the input.

**mergeBy**: (a -> a -> Ordering) -> [a] -> [a] -> [a]

Merge two sorted lists using into a single, sorted whole, allowing the programmer to specify the comparison function.

**combinePairs**: (a -> a -> a) -> [a] -> [a]

Combine elements pairwise by means of a programmer supplied function from two list inputs into a single list.

**foldBalanced1**: (a -> a -> a) -> [a] -> a

Fold a non-empty list in a balanced way. Balanced means that each element has approximately the same depth in the operator tree. Approximately the same depth means that the difference between maximum and minimum depth is at most 1. The accumulation operation must be associative and commutative in order to get the same result as

`foldl1`

or`foldr1`

.

**group**: (Eq a) => [a] -> [[a]]

The ‘group’ function groups equal elements into sublists such that the concatenation of the result is equal to the argument.

**groupBy**: (a -> a -> Bool) -> [a] -> [[a]]

The ‘groupBy’ function is the non-overloaded version of ‘group’.

**groupOn**: (Eq k) => (a -> k) -> [a] -> [[a]]

Similar to ‘group’, except that the equality is done on an extracted value.

**dedup**: (Ord a) => [a] -> [a]

`dedup l`

removes duplicate elements from a list. In particular, it keeps only the first occurence of each element. It is a special case of`dedupBy`

, which allows the programmer to supply their own equality test.`dedup`

is called`nub`

in Haskell.

**dedupBy**: (a -> a -> Ordering) -> [a] -> [a]

A version of

`dedup`

with a custom predicate.

**dedupOn**: (Ord k) => (a -> k) -> [a] -> [a]

A version of

`dedup`

where deduplication is done after applyng function. Example use:`dedupOn (.employeeNo) employees`

**dedupSort**: (Ord a) => [a] -> [a]

The

`dedupSort`

function sorts and removes duplicate elements from a list. In particular, it keeps only the first occurrence of each element.

**dedupSortBy**: (a -> a -> Ordering) -> [a] -> [a]

A version of

`dedupSort`

with a custom predicate.

**unique**: (Ord a) => [a] -> Bool

Returns True if and only if there are no duplicate elements in the given list.

**uniqueBy**: (a -> a -> Ordering) -> [a] -> Bool

A version of

`unique`

with a custom predicate.

**uniqueOn**: (Ord k) => (a -> k) -> [a] -> Bool

Returns True if and only if there are no duplicate elements in the given list after applyng function. Example use:

`assert $ uniqueOn (.employeeNo) employees`

**replace**: (Eq a) => [a] -> [a] -> [a] -> [a]

Given a list and a replacement list, replaces each occurance of the search list with the replacement list in the operation list.

**dropPrefix**: (Eq a) => [a] -> [a] -> [a]

Drops the given prefix from a list. It returns the original sequence if the sequence doesn’t start with the given prefix.

**dropSuffix**: (Eq a) => [a] -> [a] -> [a]

Drops the given suffix from a list. It returns the original sequence if the sequence doesn’t end with the given suffix.

**stripPrefix**: (Eq a) => [a] -> [a] -> Optional [a]

The

`stripPrefix`

function drops the given prefix from a list. It returns`None`

if the list did not start with the prefix given, or`Some`

the list after the prefix, if it does.

**stripSuffix**: (Eq a) => [a] -> [a] -> Optional [a]

Return the prefix of the second list if its suffix matches the entire first list.

**isPrefixOf**: (Eq a) => [a] -> [a] -> Bool

The

`isPrefixOf`

function takes two lists and returns`True`

if and only if the first is a prefix of the second.

**isSuffixOf**: (Eq a) => [a] -> [a] -> Bool

The

`isSuffixOf`

function takes two lists and returns`True`

if and only if the first list is a suffix of the second.

**isInfixOf**: (Eq a) => [a] -> [a] -> Bool

The

`isInfixOf`

function takes two lists and returns`True`

if and only if the first list is contained anywhere within the second.

**mapAccumL**: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])

The

`mapAccumL`

function combines the behaviours of`map`

and`foldl`

; it applies a function to each element of a list, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list.

**inits**: [a] -> [[a]]

The

`inits`

function returns all initial segments of the argument, shortest first.

**intersperse**: a -> [a] -> [a]

The

`intersperse`

function takes an element and a list and “intersperses” that element between the elements of the list.

**intercalate**: [a] -> [[a]] -> [a]

`intercalate`

inserts the list`xs`

in between the lists in`xss`

and concatenates the result.

**tails**: [a] -> [[a]]

The

`tails`

function returns all final segments of the argument, longest first.

**dropWhileEnd**: (a -> Bool) -> [a] -> [a]

A version of

`dropWhile`

operating from the end.

**takeWhileEnd**: (a -> Bool) -> [a] -> [a]

A version of

`takeWhile`

operating from the end.

**transpose**: [[a]] -> [[a]]

The

`transpose`

function transposes the rows and columns of its argument.

**breakEnd**: (a -> Bool) -> [a] -> ([a], [a])

Break, but from the end.

**breakOn**: (Eq a) => [a] -> [a] -> ([a], [a])

Find the first instance of

`needle`

in`haystack`

. The first element of the returned tuple is the prefix of`haystack`

before`needle`

is matched. The second is the remainder of`haystack`

, starting with the match. If you want the remainder*without*the match, use`stripInfix`

.

**breakOnEnd**: (Eq a) => [a] -> [a] -> ([a], [a])

Similar to

`breakOn`

, but searches from the end of the string.The first element of the returned tuple is the prefix of

`haystack`

up to and including the last match of`needle`

. The second is the remainder of`haystack`

, following the match.

**linesBy**: (a -> Bool) -> [a] -> [[a]]

A variant of

`lines`

with a custom test. In particular, if there is a trailing separator it will be discarded.

**wordsBy**: (a -> Bool) -> [a] -> [[a]]

A variant of

`words`

with a custom test. In particular, adjacent separators are discarded, as are leading or trailing separators.

**head**: [a] -> a

Extract the first element of a list, which must be non-empty.

**tail**: [a] -> [a]

Extract the elements after the head of a list, which must be non-empty.

**last**: [a] -> a

Extract the last element of a list, which must be finite and non-empty.

**init**: [a] -> [a]

Return all the elements of a list except the last one. The list must be non-empty.

**foldl1**: (a -> a -> a) -> [a] -> a

Left associative fold of a list that must be non-empty.

**foldr1**: (a -> a -> a) -> [a] -> a

Right associative fold of a list that must be non-empty.

**repeatedly**: ([a] -> (b, [a])) -> [a] -> [b]

Apply some operation repeatedly, producing an element of output and the remainder of the list.

**delete**: (Eq a) => a -> [a] -> [a]

`delete x`

removes the first occurrence of`x`

from its list argument. For example,> delete "a" ["b","a","n","a","n","a"] ["b","n","a","n","a"]

It is a special case of ‘deleteBy’, which allows the programmer to supply their own equality test.

**deleteBy**: (a -> a -> Bool) -> a -> [a] -> [a]

The ‘deleteBy’ function behaves like ‘delete’, but takes a user-supplied equality predicate.

> deleteBy (<=) 4 [1..10] [1,2,3,5,6,7,8,9,10]

**(\)**: (Eq a) => [a] -> [a] -> [a]

The

`\\`

function is list difference (non-associative). In the result of`xs \\ ys`

, the first occurrence of each element of`ys`

in turn (if any) has been removed from`xs`

. Thus(xs ++ ys) \\ xs == ys

Note this function is

*O(n*m)*given lists of size*n*and*m*.

**(!!)**: [a] -> Int -> a

List index (subscript) operator, starting from 0. For example,

`xs !! 2`

returns the third element in`xs`

. Raises an error if the index is not suitable for the given list. The function has complexity*O(n)*where*n*is the index given, unlike in languages such as Java where array indexing is*O(1)*.

**elemIndex**: (Eq a) => a -> [a] -> Optional Int

Find index of element in given list. Will return

`None`

if not found.

**findIndex**: (a -> Bool) -> [a] -> Optional Int

Find index, given predicate, of first matching element. Will return

`None`

if not found.

**findIndex_**- : Int -> (a -> Bool) -> [a] -> Optional Int

## Module DA.List.Total¶

### Functions¶

**head**- : (ActionFail m) => [a] -> m a

**tail**- : (ActionFail m) => [a] -> m [a]

**last**- : (ActionFail m) => [a] -> m a

**init**- : (ActionFail m) => [a] -> m [a]

**(!!)**- : (ActionFail m) => [a] -> Int -> m a

**foldl1**- : (ActionFail m) => (a -> a -> a) -> [a] -> m a

**foldr1**- : (ActionFail m) => (a -> a -> a) -> [a] -> m a

**foldBalanced1**- : (ActionFail m) => (a -> a -> a) -> [a] -> m a

## Module DA.Logic¶

Logic - Propositional calculus.

### Data Types¶

data **Formula t**

A

`Formula t`

is a formula in propositional calculus with propositions of type t.

Propositiont

`Proposition p`

is the formula p

NegationFormula tFor a formula f,

`Negation f`

is ¬f

Conjunction[Formula t]For formulas f1, …, fn,

`Conjunction [f1, ..., fn]`

is f1 ∧ … ∧ fn

Disjunction[Formula t]For formulas f1, …, fn,

`Disjunction [f1, ..., fn]`

is f1 ∧ … ∧ fn

### Functions¶

**(&&&)**: Formula t -> Formula t -> Formula t

`&&&`

is the ∧ operation of the boolean algebra of formulas, to be read as “and”

**(|||)**: Formula t -> Formula t -> Formula t

`|||`

is the ∨ operation of the boolean algebra of formulas, to be read as “or”

**true**: Formula t

`true`

is the 1 element of the boolean algebra of formulas, represented as an empty conjunction.

**false**: Formula t

`false`

is the 0 element of the boolean algebra of formulas, represented as an empty disjunction.

**neg**: Formula t -> Formula t

`neg`

is the ¬ (negation) operation of the boolean algebra of formulas.

**conj**: [Formula t] -> Formula t

`conj`

is a list version of`&&&`

, enabled by the associativity of ∧.

**disj**: [Formula t] -> Formula t

`disj`

is a list version of`|||`

, enabled by the associativity of ∧.

**fromBool**: Bool -> Formula t

`fromBool`

converts`True`

to`true`

and`False`

to`false`

.

**toNNF**: Formula t -> Formula t

`toNNF`

transforms a formula to negation normal form (see https://en.wikipedia.org/wiki/Negation_normal_form).

**toDNF**: Formula t -> Formula t

`toDNF`

turns a formula into disjunctive normal form. (see https://en.wikipedia.org/wiki/Disjunctive_normal_form).

**traverse**: (Applicative f) => (t -> f s) -> Formula t -> f (Formula s)

An implementation of

`traverse`

in the usual sense.

**zipFormulas**: Formula t -> Formula s -> Formula (t, s)

`zipFormulas`

takes to formulas of same shape, meaning only propositions are different and zips them up.

**substitute**: (t -> Optional Bool) -> Formula t -> Formula t

`substitute`

takes a truth assignment and substitutes`True`

or`False`

into the respective places in a formula.

**reduce**: Formula t -> Formula t

`reduce`

reduces a formula as far as possible by:- Removing any occurrences of
`true`

and`false`

; - Removing directly nested Conjunctions and Disjunctions;
- Going to negation normal form.

- Removing any occurrences of

**isBool**: Formula t -> Optional Bool

`isBool`

attempts to convert a formula to a bool. It satisfies`isBool true == Right True`

and`toBool false == Right False`

. Otherwise, it returns`Left x`

, where`x`

is the input.

**interpret**: (t -> Optional Bool) -> Formula t -> Either (Formula t) Bool

`interpret`

is a version of`toBool`

that first substitutes using a truth function and then reduces as far as possible.

**substituteA**: (Applicative f) => (t -> f (Optional Bool)) -> Formula t -> f (Formula t)

`substituteA`

is a version of`substitute`

that allows for truth values to be obtained from an action.

**interpretA**: (Applicative f) => (t -> f (Optional Bool)) -> Formula t -> f (Either (Formula t) Bool)

`interpretA`

is a version of`interpret`

that allows for truth values to be obtained form an action.

## Module DA.Map¶

Map - A map is an associative array data type composed of a collection of key/value pairs such that, each possible key appears at most once in the collection.

### Data Types¶

data **Map k v**

The type of a

`Map`

from keys of type`k`

to values of type`v`

.

Map_internal[(k, v)]

### Functions¶

**fromList**: (Ord k) => [(k, a)] -> Map k a

Create a map from a list of key/value pairs.

**fromListWith**: (Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a

Create a map from a list of key/value pairs with a combining function. Examples:

fromListWith (<>) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "ab"), (5, "cba")] fromListWith (<>) [] == (empty : Map Int Text)

**fromListWithKey**: (Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a

Build a map from a list of key/value pairs with a combining function. Example:

let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "3:a|b"), (5, "5:c|5:b|a")] fromListWithKey f [] == empty

**toList**: Map k v -> [(k, v)]

Convert the map to a list of key/value pairs where the keys are in ascending order.

**empty**: Map k v

The empty map.

**size**: Map k v -> Int

Number of elements in the map.

**null**: Map k v -> Bool

Is the map empty?

**lookup**: (Eq k, Ord k) => k -> Map k v -> Optional v

Lookup the value at a key in the map.

**member**: (Eq k, Ord k) => k -> Map k v -> Bool

Is the key a member of the map?

**filter**: (Eq k) => (k -> v -> Bool) -> Map k v -> Map k v

Filter all values that satisfy some predicate.

**delete**: (Eq k) => k -> Map k v -> Map k v

Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.

**insert**: (Ord k) => k -> v -> Map k v -> Map k v

Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value.

**merge**: (Ord k) => (k -> a -> Optional c) -> (k -> b -> Optional c) -> (k -> a -> b -> Optional c) -> Map k a -> Map k b -> Map k c

Merge two maps.

**union**: (Ord k) => Map k a -> Map k a -> Map k a

The union of two maps, preferring the first map when equal keys are encountered.

## Module DA.Maybe.Total¶

### Functions¶

**fromJust**- : (ActionFail m) => Optional a -> m a

**fromJustNote**- : (ActionFail m) => Text -> Optional a -> m a

## Module DA.Monoid¶

### Data Types¶

data **All**

Boolean monoid under conjunction (&&)

All

Field Type Description getAll Bool

data **Any**

Boolean Monoid under disjunction (||)

Any

Field Type Description getAny Bool

data **Endo a**

The monoid of endomorphisms under composition.

Endo

Field Type Description appEndo a -> a

## Module DA.Optional¶

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 can be built using the Either type.

### Functions¶

**fromSome**: Optional a -> a

The

`fromSome`

function extracts the element out of a`Some`

and throws an error if its argument is`None`

.

**fromSomeNote**- : Text -> Optional a -> a

**catOptionals**: [Optional a] -> [a]

The

`catOptionals`

function takes a list of`Optionals`

and returns a list of all the`Some`

values.

**listToOptional**: [a] -> Optional a

The

`listToOptional`

function returns`None`

on an empty list or`Some`

a where a is the first element of the list.

**optionalToList**: Optional a -> [a]

The

`optionalToList`

function returns an empty list when given`None`

or a singleton list when not given`None`

.

**fromOptional**: a -> Optional a -> a

The

`fromOptional`

function takes a default value and a`Optional`

value. If the`Optional`

is`None`

, it returns the default values otherwise, it returns the value contained in the`Optional`

.

**isSome**: Optional a -> Bool

The

`isSome`

function returns`True`

iff its argument is of the form`Some _`

.

**isNone**: Optional a -> Bool

The

`isNone`

function returns`True`

iff its argument is`None`

.

**mapOptional**: (a -> Optional b) -> [a] -> [b]

The

`mapOptional`

function is a version of`map`

which can throw out elements. In particular, the functional argument returns something of type`Optional b`

. If this is`None`

, no element is added on to the result list. If it is`Some b`

, then`b`

is included in the result list.

**whenSome**: (Applicative m) => Optional a -> (a -> m ()) -> m ()

Perform some operation on

`Some`

, given the field inside the`Some`

.

## Module DA.Optional.Total¶

### Functions¶

**fromSome**- : (ActionFail m) => Optional a -> m a

**fromSomeNote**- : (ActionFail m) => Text -> Optional a -> m a

## Module DA.Private.TextMap¶

TextMap - A map is an associative array data type composed of a collection of key/value pairs such that, each possible key appears at most once in the collection.

### Functions¶

**fromList**: [(Text, a)] -> TextMap a

Create a map from a list of key/value pairs.

**toList**: TextMap a -> [(Text, a)]

Convert the map to a list of key/value pairs where the keys are in ascending order.

**empty**: TextMap a

The empty map.

**size**: TextMap a -> Int

Number of elements in the map.

**null**: TextMap v -> Bool

Is the map empty?

**lookup**: Text -> TextMap a -> Optional a

Lookup the value at a key in the map.

**member**: Text -> TextMap v -> Bool

Is the key a member of the map?

**filter**: (Text -> v -> Bool) -> TextMap v -> TextMap v

Filter all values that satisfy some predicate.

**delete**: Text -> TextMap a -> TextMap a

Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.

**insert**: Text -> a -> TextMap a -> TextMap a

Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value.

**union**: TextMap a -> TextMap a -> TextMap a

The union of two maps, preferring the first map when equal keys are encountered.

## Module DA.Record¶

Exports the record machinery necessary to allow one to annotate code that is polymorphic in the underlying record type.

## Module DA.Set¶

Set - The Set e type represents a set of elements of type e. Most operations require that e be an instance of the Ord class.

### Functions¶

**empty**: Set a

The empty set.

**size**: Set a -> Int

The number of elements in the set.

**toList**: Set a -> [a]

Convert the set to a list of elements.

**fromList**: (Ord a) => [a] -> Set a

Create a set from a list of elements.

**member**: (Ord a) => a -> Set a -> Bool

Is the element in the set?

**null**: Set a -> Bool

Is this the empty set?

**insert**: (Ord a) => a -> Set a -> Set a

Insert an element in a set. If the set already contains an element equal to the given value, it is replaced with the new value.

**filter**: (Eq a) => (a -> Bool) -> Set a -> Set a

Filter all elements that satisfy the predicate.

**delete**: (Eq a) => a -> Set a -> Set a

Delete an element from a set.

**singleton**: (Ord a) => a -> Set a

Create a singleton set.

**union**: (Ord a) => Set a -> Set a -> Set a

The union of two sets, preferring the first set when equal elements are encountered.

**intersection**: (Ord a) => Set a -> Set a -> Set a

The intersection of two sets. Elements of the result come from the first set.

**difference**: (Ord a) => Set a -> Set a -> Set a

Difference of two sets.

## Module DA.Text¶

Functions for working with Text.

### Functions¶

**explode**- : Text -> [Text]

**implode**- : [Text] -> Text

**isEmpty**: Text -> Bool

Test for emptiness.

**length**: Text -> Int

Compute the number of symbols in the text.

**trim**: Text -> Text

Remove spaces from either side of the given text.

**replace**: Text -> Text -> Text -> Text

Replace a subsequence everywhere it occurs. The first argument must not be empty.

**lines**: Text -> [Text]

Breaks a

`Text`

value up into a list of`Text`

’s at newline symbols. The resulting texts do not contain newline symbols.

**unlines**: [Text] -> Text

Joins lines, after appending a terminating newline to each.

**words**: Text -> [Text]

Breaks a ‘Text’ up into a list of words, delimited by symbols representing white space.

**unwords**: [Text] -> Text

Joins words using single space symbols.

**linesBy**: (Text -> Bool) -> Text -> [Text]

A variant of

`lines`

with a custom test. In particular, if there is a trailing separator it will be discarded.

**wordsBy**: (Text -> Bool) -> Text -> [Text]

A variant of

`words`

with a custom test. In particular, adjacent separators are discarded, as are leading or trailing separators.

**intercalate**: Text -> [Text] -> Text

`intercalate`

inserts the text argument`t`

in between the items in`ts`

and concatenates the result.

**dropPrefix**: Text -> Text -> Text

`dropPrefix`

drops the given prefix from the argument. It returns the original text if the text doesn’t start with the given prefix.

**dropSuffix**: Text -> Text -> Text

Drops the given suffix from the argument. It returns the original text if the text doesn’t end with the given suffix. Examples:

dropSuffix "!" "Hello World!" == "Hello World" dropSuffix "!" "Hello World!!" == "Hello World!" dropSuffix "!" "Hello World." == "Hello World."

**stripSuffix**: Text -> Text -> Optional Text

Return the prefix of the second text if its suffix matches the entire first text. Examples:

stripSuffix "bar" "foobar" == Some "foo" stripSuffix "" "baz" == Some "baz" stripSuffix "foo" "quux" == None

**stripPrefix**: Text -> Text -> Optional Text

The

`stripPrefix`

function drops the given prefix from the argument text. It returns`None`

if the text did not start with the prefix.

**isPrefixOf**: Text -> Text -> Bool

The

`isPrefixOf`

function takes two text arguments and returns`True`

if and only if the first is a prefix of the second.

**isSuffixOf**: Text -> Text -> Bool

The

`isSuffixOf`

function takes two text arguments and returns`True`

if and only if the first is a suffix of the second.

**isInfixOf**: Text -> Text -> Bool

The

`isInfixOf`

function takes two text arguments and returns`True`

if and only if the first is contained, wholly and intact, anywhere within the second.

**takeWhile**: (Text -> Bool) -> Text -> Text

The function

`takeWhile`

, applied to a predicate`p`

and a text, returns the longest prefix (possibly empty) of symbols that satisfy`p`

.

**takeWhileEnd**: (Text -> Bool) -> Text -> Text

The function ‘takeWhileEnd’, applied to a predicate

`p`

and a ‘Text’, returns the longest suffix (possibly empty) of elements that satisfy`p`

.

**dropWhile**: (Text -> Bool) -> Text -> Text

`dropWhile p t`

returns the suffix remaining after`takeWhile p t`

.

**dropWhileEnd**: (Text -> Bool) -> Text -> Text

`dropWhileEnd p t`

returns the prefix remaining after dropping symbols that satisfy the predicate`p`

from the end of`t`

.

**splitOn**: Text -> Text -> [Text]

Break a text into pieces separated by the first text argument (which cannot be empty), consuming the delimiter.

**take**: Int -> Text -> Text

`take n`

, applied to a text`t`

, returns the prefix of`t`

of length`n`

, or`t`

itself if`n`

is greater than the length of`t`

.

**drop**: Int -> Text -> Text

`drop n`

, applied to a text`t`

, returns the suffix of`t`

after the first`n`

characters, or the empty`Text`

if`n`

is greater than the length of`t`

.

**substring**: Int -> Int -> Text -> Text

Compute the sequence of symbols of length

`l`

in the argument text starting at`s`

.

**isPred**: (Text -> Bool) -> Text -> Bool

`isPred f t`

returns`True`

if`t`

is not empty and`f`

is`True`

for all symbols in`t`

.

**isSpace**: Text -> Bool

`isSpace t`

is`True`

if`t`

is not empty and consists only of spaces.

**isNewLine**: Text -> Bool

`isSpace t`

is`True`

if`t`

is not empty and consists only of newlines.

**isUpper**: Text -> Bool

`isUpper t`

is`True`

if`t`

is not empty and consists only of uppercase symbols.

**isLower**: Text -> Bool

`isLower t`

is`True`

if`t`

is not empty and consists only of lowercase symbols.

**isDigit**: Text -> Bool

`isDigit t`

is`True`

if`t`

is not empty and consists only of digit symbols.

**isAlpha**: Text -> Bool

`isAlpha t`

is`True`

if`t`

is not empty and consists only of alphabet symbols.

**isAlphaNum**: Text -> Bool

`isAlphaNum t`

is`True`

if`t`

is not empty and consists only of alphanumeric symbols.

**parseInt_**- : [Text] -> Int -> Optional Int

**parseInt**: Text -> Optional Int

Attempt to parse an

`Int`

value from a given`Text`

.

**parsePositiveDecimal**- : [Text] -> Optional Decimal

**parseDecimal**: Text -> Optional Decimal

Attempt to parse a

`Decimal`

value from a given`Text`

. To get`Some`

value, the text must follow the regex ‘-‘?[0-9]+(‘.’[0-9]+)? In particular, the shorthands`".12"`

and`"12."`

do not work. Leading and trailing zeros are fine, however spaces are not. Examples:parseDecimal "3.14" == Some 3.14 parseDecimal "+12.0" == None

**sha256**: Text -> Text

Computes the SHA256 of the UTF8 bytes of the

`Text`

, and returns it in its hex-encoded form. The hex encoding uses lowercase letters.This function will crash at runtime if you compile DAML to DAML-LF < 1.2.

## Module DA.Time¶

### Data Types¶

data **RelTime**

The

`RelTime`

type describes a time offset, i.e. relative time.

RelTime

Field Type Description microseconds Int

### Functions¶

**time**: Date -> Int -> Int -> Int -> Time

`time d h m s`

turns given UTC date`d`

and the UTC time (given in hours, minutes, seconds) into a UTC timestamp (`Time`

). Does not handle leap seconds.

**pass**: RelTime -> Scenario Time

Pass simulated scenario time by argument

**addRelTime**: Time -> RelTime -> Time

Adjusts

`Time`

with given time offset.

**subTime**: Time -> Time -> RelTime

Returns time offset between two given instants.

**wholeDays**: RelTime -> Int

Returns the number of whole days in a time offset. Fraction of time is rounded towards zero.

**days**: Int -> RelTime

A number of days in relative time.

**hours**: Int -> RelTime

A number of hours in relative time.

**minutes**: Int -> RelTime

A number of minutes in relative time.

**seconds**- : Int -> RelTime

**convertRelTimeToMicroseconds**: RelTime -> Int

Convert RelTime to microseconds Use higher level functions instead of the internal microseconds

**convertMicrosecondsToRelTime**: Int -> RelTime

Convert microseconds to RelTime Use higher level functions instead of the internal microseconds

## Module DA.Traversable¶

Class of data structures that can be traversed from left to right, performing an action on each element.
You typically would want to import this module qualified to avoid clashes with
functions defined in Prelude. Ie.:
```
`
import DA.Traversable qualified as F
`
```

### Typeclasses¶

**class (Functor t, Foldable t) => Traversable t where**Functors representing data structures that can be traversed from left to right.

**mapA**: (Applicative f) => (a -> f b) -> t a -> f (t b)

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.

**sequence**: (Applicative f) => t (f a) -> f (t a)

Evaluate each action in the structure from left to right, and collect the results.

### Functions¶

**forA**: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)

`forA`

is`mapA`

with its arguments flipped.

## Module DA.Tuple¶

Tuple - Ubiquitous functions of tuples.

### Functions¶

**first**: (a -> a’) -> (a, b) -> (a’, b)

The pair obtained from a pair by application of a programmer supplied function to the argument pair’s first field.

**second**: (b -> b’) -> (a, b) -> (a, b’)

The pair obtained from a pair by application of a programmer supplied function to the argument pair’s second field.

**both**: (a -> b) -> (a, a) -> (b, b)

The pair obtained from a pair by application of a programmer supplied function to both the argument pair’s first and second fields.

**swap**: (a, b) -> (b, a)

The pair obtained from a pair by permuting the order of the argument pair’s first and second fields.

**dupe**: a -> (a, a)

Duplicate a single value into a pair.

> dupe 12 == (12, 12)

**fst3**: (a, b, c) -> a

Extract the ‘fst’ of a triple.

**snd3**: (a, b, c) -> b

Extract the ‘snd’ of a triple.

**thd3**: (a, b, c) -> c

Extract the final element of a triple.

**curry3**: ((a, b, c) -> d) -> a -> b -> c -> d

Converts an uncurried function to a curried function.

**uncurry3**: (a -> b -> c -> d) -> (a, b, c) -> d

Converts a curried function to a function on a triple.