The standard library

The DAML standard library is a collection of DAML modules that can be used to implement concrete applications.

Usage

The standard library is included in the DAML compiler so it can be used straight out of the box. You can import modules from the standard library just like your own, for example:

import DA.Optional
import DA.Time

Module Prelude

Typeclasses

class HasTime m where

The HasTime class is for where the time is available: Scenario and Update.

getTime

: m Time

Get the current time.

instance HasTime Scenario

instance HasTime Update

class Action m => CanAbort m where

The CanAbort class is for Action s that can be aborted.

abort

: Text -> m a

Abort the current action with a message.

instance CanAbort Scenario

instance CanAbort Update

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

instance Applicative ((->) r)

instance Applicative Scenario

instance Applicative Update

instance Applicative Down

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

(>>=)

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

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

instance Action ((->) r)

instance Action Scenario

instance Action Update

instance Action Down

instance Action Optional

instance Action Formula

instance Action NonEmpty

instance Action (Validation err)

instance Action (Either e)

instance Action ([])

class Action m => ActionFail m where

fail

: Text -> m a

Fail with an error message.

instance ActionFail Scenario

instance ActionFail Update

instance ActionFail Optional

instance ActionFail (Validation Text)

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 Semigroup (TextMap b)

instance Semigroup All

instance Semigroup Any

instance Semigroup (Endo a)

instance Multiplicative a => Semigroup (Product a)

instance Additive a => Semigroup (Sum a)

instance MapKey k => Semigroup (Map k v)

instance MapKey a => Semigroup (Set a)

instance Semigroup (NonEmpty a)

instance Ord a => Semigroup (Max a)

instance Ord a => Semigroup (Min a)

instance Semigroup Ordering

instance Semigroup Text

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 mconcat on a list of strings would concatenate all strings to one lone string.

instance Monoid (TextMap b)

instance Monoid All

instance Monoid Any

instance Monoid (Endo a)

instance Multiplicative a => Monoid (Product a)

instance Additive a => Monoid (Sum a)

instance MapKey k => Monoid (Map k v)

instance MapKey a => Monoid (Set a)

instance Monoid Ordering

instance Monoid Text

instance Monoid [a]

class Template t where

signatory

: t -> [Party]

The signatories of a contract.

observer

: t -> [Party]

The observers of a contract.

ensure

: t -> Bool

A predicate that must be true, otherwise contract creation will fail.

agreement

: t -> Text

The agreement text of a contract.

create

: t -> Update (ContractId t)

Create a contract based on a template t.

fetch

: ContractId t -> Update t

Fetch the contract data associated with the given contract ID. If the ContractId t supplied is not the contract ID of an active contract, this fails and aborts the entire transaction.

archive

: ContractId t -> Update ()

Archive the contract with the given contract ID.

toAnyTemplate

: t -> AnyTemplate

Wrap the template in AnyTemplate

fromAnyTemplate

: AnyTemplate -> Optional t

Extract the underlying template from AnyTemplate if the type matches or return None.

instance RollbackInstance i o => Template (Rollback i o)

instance UpgradeInstance i o => Template (Upgrade i o)

class Template t => Choice t c r where

exercise

: ContractId t -> c -> Update r

Exercise a choice on the contract with the given contract ID.

instance RollbackInstance i o => Choice (Rollback i o) Archive ()

instance RollbackInstance i o => Choice (Rollback i o) (DoRollback o) (ContractId i)

instance UpgradeInstance i o => Choice (Upgrade i o) Archive ()

instance UpgradeInstance i o => Choice (Upgrade i o) (DoUpgrade i) (ContractId o)

class Template t => TemplateKey t k where

key

: t -> k

The key of a contract.

lookupByKey

: k -> Update (Optional (ContractId t))

Look up the contract ID t associated with a given contract key k.

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.

fetchByKey

: k -> Update (ContractId t, t)

Fetch the contract ID and contract data associated with a given contract key.

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.

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.

instance IsParties Party

instance IsParties (Optional Party)

instance IsParties (Set Party)

instance IsParties (NonEmpty Party)

instance IsParties [Party]

class Functor f where

A Functor is a typeclass for things that can be mapped over (using its fmap function. Examples include Optional, [] and Update).

fmap

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

fmap takes a function of type a -> b, and turns it into a function of type f a -> f a, where f is the type which is an instance of Functor.

For example, map is an fmap that only works on lists. It takes a function a -> b and a [a], and returns a [b].

(<$)

: a -> f b -> f a

Replace all locations in the input f b with the same value a. The default definition is fmap . const, but you can override this with a more efficient version.

class Eq a where

The Eq class defines equality (==) and inequality (/=). All the basic datatypes exported by the “Prelude” are instances of Eq, and Eq may be derived for any datatype whose constituents are also instances of Eq.

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 = True

Symmetry: x == y = y == x

Transitivity: if x == y && y == z = True, then x == z = True

Substitutivity: if x == y = True and f is a “public” function whose return type is an instance of Eq, then f x == f y = True

Negation: 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 Bool

instance Eq Decimal

instance Eq Int

instance Eq Ordering

instance Eq Text

instance Eq a => Eq [a]

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)

class Eq a => Ord a where

The Ord class is used for totally ordered datatypes.

Instances of Ord can be derived for any user-defined datatype whose constituent types are in Ord. The declared order of the constructors in the data declaration determines the ordering in derived Ord instances. The Ordering datatype 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, then x <= z = True

Reflexivity: x <= x = True

Antisymmetry: if x <= y && y <= x = True, then x == y = True

Note that the following operator interactions are expected to hold:

  1. x >= y = y <= x
  2. x < y = x <= y && x /= y
  3. x > y = y < x
  4. x < y = compare x y == LT
  5. x > y = compare x y == GT
  6. x == y = compare x y == EQ
  7. min x y == if x <= y then x else y = ‘True’
  8. max x y == if x >= y then x else y = ‘True’

Minimal complete definition: either compare or <=. Using compare can be more efficient for complex types.

compare
: 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 Bool

instance Ord Decimal

instance Ord Int

instance Ord Ordering

instance Ord Text

instance Ord a => Ord [a]

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 Bounded a where

Use the Bounded class to name the upper and lower limits of a type.

You can derive an instance of the Bounded class for any enumeration type. minBound is the first constructor listed in the data declaration and maxBound is the last.

You can also derive an instance of Bounded for single-constructor data types whose constituent types are in Bounded.

Ord is not a superclass of Bounded because types that are not totally ordered can still have upper and lower bounds.

minBound
: a
maxBound
: a

instance Bounded Bool

instance Bounded Int

class Enum a where

Use the Enum class to define operations on sequentially ordered types: that is, types that can be enumerated. Enum members have defined successors and predecessors, which you can get with the succ and pred functions.

Types that are an instance of class Bounded as well as Enum should respect the following laws:

  • Both 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, like this:
enumFrom     x   = enumFromTo     x maxBound
enumFromThen x y = enumFromThenTo x y bound
    where
        bound | fromEnum y >= fromEnum x = maxBound
              | otherwise                = minBound
succ

: a -> a

Returns the successor of the given value. For example, for numeric types, succ adds 1.

If the type is also an instance of Bounded, succ maxBound results in a runtime error.

pred

: a -> a

Returns the predecessor of the given value. For example, for numeric types, pred subtracts 1.

If the type is also an instance of Bounded, pred minBound results in a runtime error.

toEnum

: Int -> a

Convert a value from an Int to an Enum value: ie, toEnum i returns the item at the i th position of (the instance of) Enum

fromEnum

: a -> Int

Convert a value from an Enum value to an Int: ie, returns the Int position of the element within the Enum.

If fromEnum is applied to a value that’s too large to fit in an Int, what is returned is up to your implementation.

enumFrom

: a -> [a]

Return a list of the Enum values starting at the Int position. For example:

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

: a -> a -> [a]

Returns a list of the Enum values with the first value at the first Int position, the second value at the second Int position, and further values with the same distance between them.

For example:

  • enumFromThen 4 6 : [Int] = [4,6,8,10...]
  • enumFromThen 6 2 : [Int] = [6,2,-2,-6,...,minBound :: Int]
enumFromTo

: a -> a -> [a]

Returns a list of the Enum values with the first value at the first Int position, and the last value at the last Int position.

This is what’s behind the language feature that lets you write [n,m..].

For example:

  • enumFromTo 6 10 : [Int] = [6,7,8,9,10]
enumFromThenTo

: a -> a -> a -> [a]

Returns a list of the Enum values with the first value at the first Int position, the second value at the second Int position, and further values with the same distance between them, with the final value at the final Int position.

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] = []

instance Enum Bool

instance Enum Int

class Additive a where

Use the Additive class 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
  • negate gives 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. x - y = x + negate y

negate

: a -> a

Negate the argument: x + negate x = aunit

instance Additive Decimal

instance Additive Int

class Multiplicative a where

Use the Multiplicative class 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 ^ n raises x to the power of n.

instance Multiplicative Decimal

instance Multiplicative Int

class (Additive a, Multiplicative a) => Number a where

Number is a class for numerical types. As well as the rules for Additive and Multiplicative, 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 Number Decimal

instance Number Int

class Signed a where

The Signed is for the sign of a number.

signum

: a -> a

Sign of a number. For real numbers, the ‘signum’ is either -1 (negative), 0 (zero) or 1 (positive).

abs

: a -> a

The absolute value: that is, the value without the sign.

instance Signed Decimal

instance Signed Int

class Multiplicative a => Divisible a where

Use the Divisible class for types that can be divided. Instances should respect that division is the inverse of multiplication, i.e. x * y / y is equal to x whenever it is defined.

(/)

: a -> a -> a

x / y divides x by y

instance Divisible Decimal

instance Divisible Int

class Divisible a => Fractional a where

Use the Fractional class for types that can be divided and where the reciprocal is well defined. Instances have to respect the following laws:

  • When recip x is defined, it must be the inverse of x with respect to multiplication: x * recip x = munit
  • When recip y is defined, then x / y = x * recip y
recip

: a -> a

Calculates the reciprocal: recip x is 1/x.

instance Fractional Decimal

class Show a where

Use the Show class for values that can be converted to a readable Text value.

Derived instances of Show have the following properties:

  • The result of show is 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 showsPrec produces infix applications of the constructor.
  • If the precedence of the top-level constructor in x is less than d (associativity is ignored), the representation will be enclosed in parentheses. For example, 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.
showsPrec

: Int -> a -> ShowS

Convert a value to a readable Text value. Unlike show, showsPrec should satisfy the rule showsPrec d x r ++ s == showsPrec d x (r ++ s)

show

: a -> Text

Convert a value to a readable Text value.

showList

: [a] -> ShowS

Allows you to show lists of values.

instance (Show a, Show b) => Show (Either a b)

instance Show Bool

instance Show Decimal

instance Show Int

instance Show Text

instance Show a => Show [a]

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)

Orphan Typeclass Instances

instance Functor a

instance Functor ([])

instance Functor ((->) r)

instance Functor (Either e)

Data Types

data AnyTemplate

Existential template type that can wrap an arbitrary template.

data ContractId a

The ContractId a type represents an ID for a contract created from a template a. You can use the ID to fetch the contract, among other things.

instance HasField “inC” (DoRollback o) (ContractId o)

instance HasField “inC” (DoUpgrade i) (ContractId i)

instance RollbackInstance i o => Choice (Rollback i o) (DoRollback o) (ContractId i)

instance UpgradeInstance i o => Choice (Upgrade i o) (DoUpgrade i) (ContractId o)

instance Eq (ContractId a)

instance Show (ContractId a)

data Date

The Date type represents a date, for example date 2007 Apr 5.

instance Eq Date

instance Ord Date

instance Show Date

data Party

The Party type represents a party to a contract.

instance HasField “op” (Rollback i o) Party

instance HasField “op” (Upgrade i o) Party

instance HasField “sigs” (DoRollback o) [Party]

instance HasField “sigs” (DoUpgrade i) [Party]

instance IsParties Party

instance IsParties (Optional Party)

instance IsParties (Set Party)

instance IsParties (NonEmpty Party)

instance IsParties [Party]

instance MapKey Party

instance Eq Party

instance Ord Party

instance Show Party

data Scenario a

The Scenario type is for simulating 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.

instance CanAbort Scenario

instance HasTime Scenario

instance Action Scenario

instance ActionFail Scenario

instance Applicative Scenario

instance Functor Scenario

data TextMap a

The TextMap a type represents an associative array from keys of type Text to values of type a.

instance Foldable TextMap

instance Monoid (TextMap b)

instance Semigroup (TextMap b)

instance HasField “textMap” (Map k v) (TextMap v)

instance HasField “textMap” (Set a) (TextMap ())

instance Traversable TextMap

instance Functor TextMap

instance Eq a => Eq (TextMap a)

instance Ord a => Ord (TextMap a)

instance Show a => Show (TextMap a)

data Time

The Time type represents a specific datetime in UTC, for example time (date 2007 Apr 5) 14 30 05.

instance Eq Time

instance Ord Time

instance Show Time

data Update a

The Update a type represents an Action to update or query the ledger, before returning a value of type a. Examples include create and fetch.

instance CanAbort Update

instance HasTime Update

instance Action Update

instance ActionFail Update

instance Applicative Update

instance Functor Update

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.

Down a

instance Action Down

instance Applicative Down

instance Functor Down

instance Eq a => Eq (Down a)

instance Ord a => Ord (Down a)

instance Show a => Show (Down a)

data Optional a

The Optional type encapsulates an optional value. A value of type Optional a either contains a value of type a (represented as Some a), or it is empty (represented as None). Using Optional is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error.

The Optional type is also an Action. It is a simple kind of error Action, where all errors are represented by None. A richer error Action could be built using the Data.Either.Either type.

None

Some a

instance Foldable Optional

instance Action Optional

instance ActionFail Optional

instance Applicative Optional

instance IsParties (Optional Party)

instance Traversable Optional

instance Functor Optional

instance Eq a => Eq (Optional a)

instance Ord a => Ord (Optional a)

instance Show a => Show (Optional a)

data Archive

The data type corresponding to the implicit Archive choice in every template.

Archive

instance RollbackInstance i o => Choice (Rollback i o) Archive ()

instance UpgradeInstance i o => Choice (Upgrade i o) Archive ()

instance Eq Archive

instance Show Archive

data HasKey t

data NonConsuming t

data PostConsuming t

data PreConsuming t

type ShowS

= Text -> Text

showS should represent some text, and applying it to some argument should prepend the argument to the represented text.

data Bool

A type for Boolean values, ie True and False.

False

True

instance Eq Bool

instance Ord Bool

instance Bounded Bool

instance Enum Bool

instance Show Bool

data Decimal

A type for fixed-point decimals: numbers of the form x / 10e10 where x is an integer with |x| < 10e38. For example, 1.25.

instance Eq Decimal

instance Ord Decimal

instance Additive Decimal

instance Divisible Decimal

instance Fractional Decimal

instance Multiplicative Decimal

instance Number Decimal

instance Signed Decimal

instance Show Decimal

data Int

A type representing a 64-bit integer.

instance Eq Int

instance Ord Int

instance Bounded Int

instance Enum Int

instance Additive Int

instance Divisible Int

instance Multiplicative Int

instance Number Int

instance Signed Int

instance Show Int

data Ordering

A type for giving information about ordering: being less than (LT), equal to (EQ), or greater than (GT) something.

LT

EQ

GT

instance Eq Ordering

instance Ord Ordering

data Symbol

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

data Text

A type for text strings, that can represent any unicode code point. For example "Hello, world".

instance Eq Text

instance Ord Text

instance Show Text

Functions

assert

: CanAbort m => Bool -> m ()

Check whether a condition is true. If it’s not, abort the transaction.

assertMsg

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

Check whether a condition is true. If it’s not, abort the transaction with a message.

assertAfter

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

Check whether the given time is in the future. If it’s not, abort the transaction.

assertBefore

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

Check whether the given time is in the past. If it’s not, abort the transaction.

daysSinceEpochToDate

: Int -> Date

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

dateToDaysSinceEpoch

: Date -> Int

Convert from a date to number of days from 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. In most cases, you should use show instead. show 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.

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 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, and the update is expected to fail. Therefore, this scenario fails if the underlying update action succeeds.

scenario

: Scenario a -> Scenario a

Declare you are building a scenario.

($)

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

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.

(>>)

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

return

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

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

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.

length

: [a] -> Int

Gives the length of the list.

any

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

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

all

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

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.

or

: [Bool] -> Bool

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.

and

: [Bool] -> Bool

Is every element in a list of Bool true? and bs is True if every element of bs is True.

elem

: Eq a => a -> [a] -> Bool

Does this value exist in this list? elem x xs is True if x is an element of the list xs.

notElem

: Eq a => a -> [a] -> Bool

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.

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.

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)
""
either

: (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
concat

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

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

enumerate

: (Enum a, Bounded a) => [a]

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

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 takes a function and two lists. It generalises zip by combining elements using the function, instead of forming pairs. If one list is shorter, the excess elements of the longer list are discarded.

zipWith3

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

zipWith3 generalises zip3 by combining elements using the function, instead of forming triples.

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

snd

: (a, b) -> b

Return the second element of a tuple.

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 a Decimal to the nearest integer, where a .5 is rounded away from zero.

floor

: Decimal -> Int

Round a Decimal down to the nearest integer.

ceiling

: Decimal -> Int

Round a Decimal up to the nearest integer.

null

: [a] -> Bool

Is the list empty? null xs is true if xs is the empty list.

filter

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

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

stakeholder

: Template t => t -> [Party]

The stakeholders of a contract: its signatories and observers.

exerciseByKey

: (TemplateKey t k, Choice t c r) => k -> c -> Update r

Exercise a choice on the contract associated with the given key.

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.

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

foldr

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

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]
(&&)

: Bool -> Bool -> Bool

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.

(||)

: Bool -> Bool -> Bool

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.

not

: Bool -> Bool

Boolean “not”

error
: Text -> a
(%)

: Int -> Int -> Int

x % y calculates the remainder of x by y

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

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.

Module Control.Exception.Base

Functions

absentSumFieldError
: 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

Functions

(===)

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

Check two values for equality. If they’re not equal, fail with a message.

assertAfterMsg

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

Check whether the given time is in the future. If it’s not, abort with a message.

assertBeforeMsg

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

Check whether the given time is in the past. If it’s not, 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.

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' 'identity' 'identity'  'identity'@

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

@
'first' 'identity'  'identity'
'second' 'identity'  'identity'
@

If you supply both, you should also ensure:

@'bimap' f g  'first' f '.' 'second' g@
```

By parametricity, these will ensure that:

```
@
'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
@
```
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 not (+1) (True, 3)
(False,4)

>>> bimap not (+1) (Left True)
Left False

>>> bimap not (+1) (Right 3)
Right 4
first

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

Map covariantly over the first argument.

@'first' f  'bimap' f 'identity'@
```

Examples:

```
>>> first not (True, 3)
(False,3)

>>> first not (Left True : Either Bool Int)
Left False
```
second

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

Map covariantly over the second argument.

@'second'  'bimap' 'identity'@

Examples:

>>> second (+1) (True, 3)
(True,4)

>>> second (+1) (Right 3 : Either Bool Int)
Right 4

instance Bifunctor Either

instance Bifunctor ()

instance Bifunctor x1

instance Bifunctor (x1, x2)

instance Bifunctor (x1, x2, x3)

instance Bifunctor (x1, x2, x3, x4)

instance Bifunctor (x1, x2, x3, x4, x5)

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

instance Eq DayOfWeek

instance Ord DayOfWeek

instance Bounded DayOfWeek

instance Enum DayOfWeek

instance Show DayOfWeek

data Month

The Month type represents a month in the Gregorian calendar.

Jan

Feb

Mar

Apr

May

Jun

Jul

Aug

Sep

Oct

Nov

Dec

instance Eq Month

instance Ord Month

instance Bounded Month

instance Enum Month

instance Show Month

Functions

addDays

: Date -> Int -> Date

Add the given number of days to a date.

subDate

: Date -> Date -> Int

Returns the number of days between the two given dates.

dayOfWeek

: Date -> DayOfWeek

Returns the day of week for the 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 a (year, month, day) triple, according to the Gregorian calendar.

date

: Int -> Month -> Int -> Date

Given the three values (year, month, day), constructs a Date value. date (y, m, d) turns the year y, month m, and day d into a Date value.

isLeapYear

: Int -> Bool

Returns True if 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 the given month in the 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

Within a scenario, pass the 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 from a list.

rights

: [Either a b] -> [b]

Extracts all the Right elements from a list.

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 in case of a Right-value.

fromRight

: b -> Either a b -> b

Return the contents of a Right-value, or a default value in case of a Left-value.

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. It’s a good idea 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.

instance Foldable TextMap

instance Foldable Optional

instance Foldable (Map k)

instance Foldable NonEmpty

instance Foldable (Either a)

instance Foldable ([])

instance Foldable a

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

Typeclasses

class Generic a rep where

Representable types of kind @*@. This class is derivable in DAML with the @DeriveGeneric@ flag on.

A ‘Generic’ instance must satisfy the following laws:

'from' . 'to'  'Prelude.id'
'to' . 'from'  'Prelude.id'

[DA] we replaced the type family @Rep a@ with a second type parameter of the class @rep@.

from

: a -> rep x

Convert from the datatype to its representation

to

: rep x -> a

Convert from the representation to the datatype

class Generic1 f rep where

Representable types of kind * -> * (or kind k -> *, when @PolyKinds@ is enabled). This class is derivable in GHC with the @DeriveGeneric@ flag on.

A ‘Generic1’ instance must satisfy the following laws:

'from1' . 'to1'  'Prelude.id'
'to1' . 'from1'  'Prelude.id'

[DA] we replaced the type family @Rep1 f@ with a second type paremeter of the class @rep@.

from1

: f a -> rep a

Convert from the datatype to its representation

to1

: rep a -> f a

Convert from the representation to the datatype

Data Types

data :*: f g p

P1

Field Type Description
prodL1 f p  
prodR1 g p  

instance GenConvertible a1 a2 => GenConvertible a1 ((:*:) a2 (Opt b s))

instance (GenConvertible a1 a2, GenConvertible b1 b2) => GenConvertible ((:*:) a1 b1) ((:*:) a2 b2)

instance GenConvertible a1 a2 => GenConvertible ((:*:) a1 (Opt b1 s)) a2

instance (Iso a1 a2, Iso b1 b2) => Iso ((:*:) a1 b1) ((:*:) a2 b2)

instance (Eq (f p), Eq (g p)) => Eq ((:*:) f g p)

instance (Ord (f p), Ord (g p)) => Ord ((:*:) f g p)

instance (Show (f p), Show (g p)) => Show ((:*:) f g p)

data :+: f g p

L1 (f p)

R1 (g p)

instance (GenConvertible a1 a2, GenConvertible b1 b2) => GenConvertible ((:+:) a1 b1) ((:+:) a2 b2)

instance (Iso a1 a2, Iso b1 b2) => Iso ((:+:) a1 b1) ((:+:) a2 b2)

instance (Eq (f p), Eq (g p)) => Eq ((:+:) f g p)

instance (Ord (f p), Ord (g p)) => Ord ((:+:) f g p)

instance (Show (f p), Show (g p)) => Show ((:+:) f g p)

data :.: f g p

Comp1

Field Type Description
unComp1 f (g p)  

instance Eq (f (g p)) => Eq ((:.:) f g p)

instance Ord (f (g p)) => Ord ((:.:) f g p)

instance Show (f (g p)) => Show ((:.:) f g p)

data Associativity

Datatype to represent the associativity of a constructor

LeftAssociative

RightAssociative

NotAssociative

instance Eq Associativity

instance Ord Associativity

instance Bounded Associativity

instance Enum Associativity

instance Show Associativity

data C

Tag for M1: constructor
type C1

= M1 C

Type synonym for encoding meta-information for constructors

data D

Tag for M1: datatype
type D1

= M1 D

Type synonym for encoding meta-information for datatypes

data DecidedStrictness

The strictness that GHC infers for a field during compilation. Whereas there are nine different combinations of ‘SourceUnpackedness’ and ‘SourceStrictness’, the strictness that GHC decides will ultimately be one of lazy, strict, or unpacked. What GHC decides is affected both by what the user writes in the source code and by GHC flags. As an example, consider this data type:

data E = ExampleConstructor {\-\# UNPACK \#-\} !Int !Int Int
  • If compiled without optimization or other language extensions, then the fields of @ExampleConstructor@ will have ‘DecidedStrict’, ‘DecidedStrict’, and ‘DecidedLazy’, respectively.
  • If compiled with @-XStrictData@ enabled, then the fields will have ‘DecidedStrict’, ‘DecidedStrict’, and ‘DecidedStrict’, respectively.
  • If compiled with @-O2@ enabled, then the fields will have ‘DecidedUnpack’, ‘DecidedStrict’, and ‘DecidedLazy’, respectively.

DecidedLazy

DecidedStrict

DecidedUnpack

instance Eq DecidedStrictness

instance Ord DecidedStrictness

instance Bounded DecidedStrictness

instance Enum DecidedStrictness

instance Show DecidedStrictness

data Fixity

Datatype to represent the fixity of a constructor. An infix declaration directly corresponds to an application of ‘Infix’.

Prefix

Infix Infix0

instance Eq Fixity

instance Ord Fixity

instance Show Fixity

data FixityI

This variant of ‘Fixity’ appears at the type level.

PrefixI

InfixI InfixI0

data K1 i c p

Constants, additional parameters and recursion of kind @*@

K1

Field Type Description
unK1 c  

instance GenConvertible (K1 R c) (K1 R c)

instance GenConvertible c1 c2 => GenConvertible (K1 R (c1 x)) (K1 R (c2 x))

instance (Generic x repX, Generic y repY, GenConvertible repX repY) => GenConvertible (K1 R x) (K1 R y)

instance Iso (K1 R c) (K1 R c)

instance Iso c1 c2 => Iso (K1 R (c1 x)) (K1 R (c2 x))

instance (Generic x repX, Generic y repY, Iso repX repY) => Iso (K1 R x) (K1 R y)

instance Eq c => Eq (K1 i c p)

instance Ord c => Ord (K1 i c p)

instance Show c => Show (K1 i c p)

data M1 i c f p

Meta-information (constructor names, etc.)

M1

Field Type Description
unM1 f p  

instance (MetaEquiv c1 c2, GenConvertible f1 f2) => GenConvertible (M1 i1 c1 f1) (M1 i2 c2 f2)

instance Iso f1 f2 => Iso (M1 i1 c1 f1) (M1 i2 c2 f2)

instance Eq (f p) => Eq (M1 i c f p)

instance Ord (f p) => Ord (M1 i c f p)

instance Show (f p) => Show (M1 i c f p)

data Meta

Datatype to represent metadata associated with a datatype (@MetaData@), constructor (@MetaCons@), or field selector (@MetaSel@).

  • In @MetaData n m p nt@, @n@ is the datatype’s name, @m@ is the module in which the datatype is defined, @p@ is the package in which the datatype is defined, and @nt@ is @’True@ if the datatype is a @newtype@.
  • In @MetaCons n f s@, @n@ is the constructor’s name, @f@ is its fixity, and @s@ is @’True@ if the constructor contains record selectors.
  • In @MetaSel mn su ss ds@, if the field uses record syntax, then @mn@ is ‘Just’ the record name. Otherwise, @mn@ is ‘Nothing’. @su@ and @ss@ are the field’s unpackedness and strictness annotations, and @ds@ is the strictness that GHC infers for the field.

MetaData MetaData0

MetaCons MetaCons0

MetaSel MetaSel0

data MetaCons0

MetaCons0

Field Type Description
name Symbol  
fixity FixityI  
hasRecordSelectors Bool  

data MetaData0

MetaData0

Field Type Description
name Symbol  
module_ Symbol  
package Symbol  
isNewType Bool  

instance MetaEquiv (MetaData (MetaData0 n mod p1 False)) (MetaData (MetaData0 n mod p2 False))

instance MetaEquiv (MetaData (MetaData0 n mod p1 True)) (MetaData (MetaData0 n mod p2 True))

data MetaSel0

MetaSel0

Field Type Description
mbRecordName Optional Symbol  
sourceUnpackedness SourceUnpackedness  
sourceStrictness SourceStrictness  

data Par1 p

Used for marking occurrences of the parameter

Par1

Field Type Description
unPar1 p  

instance Eq p => Eq (Par1 p)

instance Ord p => Ord (Par1 p)

instance Show p => Show (Par1 p)

data R

Tag for K1: recursion (of kind @Type@)

instance GenConvertible (K1 R c) (K1 R c)

instance GenConvertible c1 c2 => GenConvertible (K1 R (c1 x)) (K1 R (c2 x))

instance (Generic x repX, Generic y repY, GenConvertible repX repY) => GenConvertible (K1 R x) (K1 R y)

instance Iso (K1 R c) (K1 R c)

instance Iso c1 c2 => Iso (K1 R (c1 x)) (K1 R (c2 x))

instance (Generic x repX, Generic y repY, Iso repX repY) => Iso (K1 R x) (K1 R y)

type Rec0

= K1 R

Type synonym for encoding recursion (of kind @Type@)

data Rec1 f p

Recursive calls of kind * -> * (or kind k -> *, when @PolyKinds@ is enabled)

Rec1

Field Type Description
unRec1 f p  

instance Eq (f p) => Eq (Rec1 f p)

instance Ord (f p) => Ord (Rec1 f p)

instance Show (f p) => Show (Rec1 f p)

data S

Tag for M1: record selector
type S1

= M1 S

Type synonym for encoding meta-information for record selectors

data SourceStrictness

The strictness of a field as the user wrote it in the source code. For example, in the following data type:

data E = ExampleConstructor Int ~Int !Int

The fields of @ExampleConstructor@ have ‘NoSourceStrictness’, ‘SourceLazy’, and ‘SourceStrict’, respectively.

NoSourceStrictness

SourceLazy

SourceStrict

instance Eq SourceStrictness

instance Ord SourceStrictness

instance Bounded SourceStrictness

instance Enum SourceStrictness

instance Show SourceStrictness

data SourceUnpackedness

The unpackedness of a field as the user wrote it in the source code. For example, in the following data type:

data E = ExampleConstructor     Int
           {\-\# NOUNPACK \#-\} Int
           {\-\#   UNPACK \#-\} Int

The fields of @ExampleConstructor@ have ‘NoSourceUnpackedness’, ‘SourceNoUnpack’, and ‘SourceUnpack’, respectively.

NoSourceUnpackedness

SourceNoUnpack

SourceUnpack

instance Eq SourceUnpackedness

instance Ord SourceUnpackedness

instance Bounded SourceUnpackedness

instance Enum SourceUnpackedness

instance Show SourceUnpackedness

data U1 p

Unit: used for constructors without arguments

U1

instance GenConvertible U1 U1

instance Iso U1 U1

instance Eq (U1 p)

instance Ord (U1 p)

instance Show (U1 p)

data V1 p

Void: used for datatypes without constructors

instance GenConvertible V1 V1

instance Iso V1 V1

instance Eq (V1 p)

instance Ord (V1 p)

instance Show (V1 p)

Functions

prec

: Fixity -> Int

Get the precedence of a fixity value.

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 String
= Text
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

Module DA.Internal.Desugar

Automatically imported qualified in every module.

Module DA.Internal.RebindableSyntax

Automatically imported unqualified in every module.

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.

stripInfix

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

Return the string before and after the search string or None if the search string is not found.

>>> stripInfix [0,0] [1,0,0,2,0,0,3]
Some ([1], [2,0,0,3])

>>> stripInfix [0,0] [1,2,0,4,5]
None
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.

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.

Proposition t

Proposition p is the formula p

Negation (Formula t)

For 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

instance Action Formula

instance Applicative Formula

instance Functor Formula

instance Eq t => Eq (Formula t)

instance Ord t => Ord (Formula t)

instance Show t => Show (Formula t)

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:

  1. Removing any occurrences of true and false;
  2. Removing directly nested Conjunctions and Disjunctions;
  3. Going to negation normal form.
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.Math

Math - Utility Math functions for Decimal The this library is designed to give good precision, typically giving 9 correct decimal places. The numerical algorithms run with many iterations to achieve that precision and are interpreted by the DAML runtime so they are not performant. Their use is not advised in performance critical contexts.

Functions

(**)

: Decimal -> Decimal -> Decimal

Take a power of a number Example: 2.0 ** 2.0 == 4.0.

exp

: Decimal -> Decimal

The exponential function. Example: exp 0.0 == 1.0

log

: Decimal -> Decimal

The natural logarithm. Example: log 10.0 == 2.30258509299

logBase

: Decimal -> Decimal -> Decimal

The logarithm of a number to a given base. Example: log 10.0 100.0 == 2.0

sin

: Decimal -> Decimal

sin is the sine function

cos

: Decimal -> Decimal

cos is the cosine function

tan

: Decimal -> Decimal

tan is the tangent function

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  

instance Monoid All

instance Semigroup All

instance HasField “getAll” All Bool

instance Eq All

instance Ord All

instance Show All

data Any

Boolean Monoid under disjunction (||)

Any

Field Type Description
getAny Bool  

instance Monoid Any

instance Semigroup Any

instance HasField “getAny” Any Bool

instance Eq Any

instance Ord Any

instance Show Any

data Endo a

The monoid of endomorphisms under composition.

Endo

Field Type Description
appEndo a -> a  

instance Monoid (Endo a)

instance Semigroup (Endo a)

instance HasField “appEndo” (Endo a) (a -> a)

data Product a

Monoid under (*)

> Product 2 <> Product 3
Product 6

Product a

instance Multiplicative a => Monoid (Product a)

instance Multiplicative a => Semigroup (Product a)

instance Eq a => Eq (Product a)

instance Ord a => Ord (Product a)

instance Additive a => Additive (Product a)

instance Multiplicative a => Multiplicative (Product a)

instance Show a => Show (Product a)

data Sum a

Monoid under (+)

> Sum 1 <> Sum 2
Sum 3

Sum a

instance Additive a => Monoid (Sum a)

instance Additive a => Semigroup (Sum a)

instance Eq a => Eq (Sum a)

instance Ord a => Ord (Sum a)

instance Additive a => Additive (Sum a)

instance Multiplicative a => Multiplicative (Sum a)

instance Show a => Show (Sum a)

Module DA.Next.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.

Typeclasses

class Eq k => MapKey k where

A class for types that can be used as keys for the Map type. All keys k must satisfy keyFromText (keyToText k) == k.

keyToText

: k -> Text

Turn a key into its textual representation. This function must be injective.

keyFromText

: Text -> k

Recover a key from its textual representation. keyFromText x is allowed to fail whenever there is no key k with keyToText k == x. Whenever such a k does exist, then it must satisfy keyFromText x == k.

instance MapKey Party

instance MapKey Decimal

instance MapKey Int

instance MapKey Text

Data Types

data Map k v

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

instance Foldable (Map k)

instance MapKey k => Monoid (Map k v)

instance MapKey k => Semigroup (Map k v)

instance HasField “textMap” (Map k v) (TextMap v)

instance MapKey k => Traversable (Map k)

instance MapKey k => Functor (Map k)

instance Eq v => Eq (Map k v)

instance Ord v => Ord (Map k v)

instance (MapKey k, Show k, Show v) => Show (Map k v)

Functions

fromList

: MapKey k => [(k, v)] -> Map k v

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

fromListWith

: MapKey k => (v -> v -> v) -> [(k, v)] -> Map k v

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, "ba"), (5, "abc")]
fromListWith (<>) [] == (empty : Map Int Text)
toList

: MapKey k => Map k v -> [(k, v)]

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

fromTextMap

: TextMap v -> Map Text v

Create a Map from a TextMap.

toTextMap

: MapKey k => Map k v -> TextMap v

Convert a Map into a TextMap.

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

: MapKey k => k -> Map k v -> Optional v

Lookup the value at a key in the map.

member

: MapKey k => k -> Map k v -> Bool

Is the key a member of the map?

filterWithKey

: MapKey k => (k -> v -> Bool) -> Map k v -> Map k v

Filter all values that satisfy some predicate.

delete

: MapKey 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

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

union

: MapKey k => Map k v -> Map k v -> Map k v

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

merge

: MapKey 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. merge f g h x y applies f to all key/value pairs whose key only appears in x, g to all pairs whose key only appears in y and h to all pairs whose key appears in both x and y. In the end, all pairs yielding Some are collected as the result.

Module DA.Next.Set

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

Data Types

data Set a

The type of a set.

instance MapKey a => Monoid (Set a)

instance MapKey a => Semigroup (Set a)

instance HasField “textMap” (Set a) (TextMap ())

instance IsParties (Set Party)

instance Eq (Set a)

instance Ord (Set a)

instance (MapKey a, Show a) => Show (Set a)

Functions

empty

: Set a

The empty set.

size

: Set a -> Int

The number of elements in the set.

toList

: MapKey a => Set a -> [a]

Convert the set to a list of elements.

fromList

: MapKey a => [a] -> Set a

Create a set from a list of elements.

toTextMap

: Set Text -> TextMap ()

Convert a Set into a TextMap.

fromTextMap

: TextMap () -> Set Text

Create a Set from a TextMap.

member

: MapKey a => a -> Set a -> Bool

Is the element in the set?

null

: Set a -> Bool

Is this the empty set?

insert

: MapKey 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

: MapKey a => (a -> Bool) -> Set a -> Set a

Filter all elements that satisfy the predicate.

delete

: MapKey a => a -> Set a -> Set a

Delete an element from a set.

singleton

: MapKey a => a -> Set a

Create a singleton set.

union

: MapKey a => Set a -> Set a -> Set a

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

intersection

: MapKey a => Set a -> Set a -> Set a

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

difference

: MapKey a => Set a -> Set a -> Set a

Difference of two sets.

Module DA.NonEmpty

Type and functions for non-empty lists. This module re-exports many functions with the same name as prelude list functions, so it is expected to import the module qualified. For example, with the following import list you will have access to the NonEmpty type and any functions on non-empty lists will be qualified, for example as NE.append, NE.map, NE.foldl:

import DA.NonEmpty (NonEmpty)
import qualified DA.NonEmpty as NE

Data Types

data NonEmpty a

NonEmpty is the type of non-empty lists. In other words, it is the type of lists that always contain at least one element. If x is a non-empty list, you can obtain the first element with x.hd and the rest of the list with x.tl.

NonEmpty

Field Type Description
hd a  
tl [a]  

instance Foldable NonEmpty

instance Action NonEmpty

instance Applicative NonEmpty

instance Semigroup (NonEmpty a)

instance HasField “hd” (NonEmpty a) a

instance HasField “tl” (NonEmpty a) [a]

instance IsParties (NonEmpty Party)

instance Traversable NonEmpty

instance Functor NonEmpty

instance Eq a => Eq (NonEmpty a)

instance Show a => Show (NonEmpty a)

Functions

append

: NonEmpty a -> NonEmpty a -> NonEmpty a

Append or concatenate two non-empty lists.

map

: (a -> b) -> NonEmpty a -> NonEmpty b

Apply a function over each element in the non-empty list.

nonEmpty

: [a] -> Optional (NonEmpty a)

Turn a list into a non-empty list, if possible. Returns None if the input list is empty, and Some otherwise.

singleton

: a -> NonEmpty a

A non-empty list with a single element.

toList

: NonEmpty a -> [a]

Turn a non-empty list into a list (by forgetting that it is not empty).

reverse

: NonEmpty a -> NonEmpty a

Reverse a non-empty list.

foldl1

: (a -> a -> a) -> NonEmpty a -> a

Apply a function repeatedly to pairs of elements from a non-empty list, from the left. For example, foldl1 (+) (NonEmpty 1 [2,3,4]) = ((1 + 2) + 3) + 4.

foldr1

: (a -> a -> a) -> NonEmpty a -> a

Apply a function repeatedly to pairs of elements from a non-empty list, from the right. For example, foldr1 (+) (NonEmpty 1 [2,3,4]) = 1 + (2 + (3 + 4)).

foldr

: (a -> b -> b) -> b -> NonEmpty a -> b

Apply a function repeatedly to pairs of elements from a non-empty list, from the right, with a given initial value. For example, foldr (+) 0 (NonEmpty 1 [2,3,4]) = 1 + (2 + (3 + (4 + 0))).

foldrA

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

The same as foldr but running an action each time.

foldr1A

: Action m => (a -> a -> m a) -> NonEmpty a -> m a

The same as foldr1 but running an action each time.

foldl

: (b -> a -> b) -> b -> NonEmpty a -> b

Apply a function repeatedly to pairs of elements from a non-empty list, from the left, with a given initial value. For example, foldl (+) 0 (NonEmpty 1 [2,3,4]) = (((0 + 1) + 2) + 3) + 4.

foldlA

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

The same as foldl but running an action each time.

foldl1A

: Action m => (a -> a -> m a) -> NonEmpty a -> m a

The same as foldl1 but running an action each time.

Module DA.Numeric

Functions

pi

: Decimal

The number pi.

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

Typeclasses

class HasField x r a where

getField
: r -> a
setField
: a -> r -> r

instance HasField “_1” (a, b) a

instance HasField “_1” (a, b, c) a

instance HasField “_1” (a, b, c, d) a

instance HasField “_1” (a, b, c, d, e) a

instance HasField “_2” (a, b) b

instance HasField “_2” (a, b, c) b

instance HasField “_2” (a, b, c, d) b

instance HasField “_2” (a, b, c, d, e) b

instance HasField “_3” (a, b, c) c

instance HasField “_3” (a, b, c, d) c

instance HasField “_3” (a, b, c, d, e) c

instance HasField “_4” (a, b, c, d) d

instance HasField “_4” (a, b, c, d, e) d

instance HasField “_5” (a, b, c, d, e) e

instance HasField “appEndo” (Endo a) (a -> a)

instance HasField “getAll” All Bool

instance HasField “getAny” Any Bool

instance HasField “hd” (NonEmpty a) a

instance HasField “inC” (DoRollback o) (ContractId o)

instance HasField “inC” (DoUpgrade i) (ContractId i)

instance HasField “op” (Rollback i o) Party

instance HasField “op” (Upgrade i o) Party

instance HasField “sigs” (DoRollback o) [Party]

instance HasField “sigs” (DoUpgrade i) [Party]

instance HasField “textMap” (Map k v) (TextMap v)

instance HasField “textMap” (Set a) (TextMap ())

instance HasField “tl” (NonEmpty a) [a]

Module DA.Semigroup

Data Types

data Max a

Semigroup under max

> Max 23 <> Max 42
Max 42

Max a

instance Ord a => Semigroup (Max a)

instance Eq a => Eq (Max a)

instance Ord a => Ord (Max a)

instance Show a => Show (Max a)

data Min a

Semigroup under min

> Min 23 <> Min 42
Min 23

Min a

instance Ord a => Semigroup (Min a)

instance Eq a => Eq (Min a)

instance Ord a => Ord (Min a)

instance Show a => Show (Min a)

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.

splitAt

: Int -> Text -> (Text, Text)

Split a text before a given position so that for 0 <= n <= length t, length (fst (splitAt n t)) == n.

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 -> Optional Int

Attempt to parse an Int value from a given Text.

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, but the value can be prefixed with +. Leading and trailing zeros are fine, however spaces are not. Examples:

parseDecimal "3.14" == Some 3.14
parseDecimal "+12.0" == Some 12
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.

reverse

: Text -> Text

Reverse some Text.

reverse "DAML" == "LMAD"
toCodePoints

: Text -> [Int]

Convert a Text into a sequence of unicode code points.

fromCodePoints

: [Int] -> Text

Convert a sequence of unicode code points into a Text. Raises an exception if any of the code points is invalid.

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

Orphan Typeclass Instances

instance Show a => Show (TextMap a)

instance Eq a => Eq (TextMap a)

instance Ord a => Ord (TextMap a)

instance Semigroup (TextMap b)

instance Monoid (TextMap b)

instance Functor TextMap

instance Foldable TextMap

instance Traversable TextMap

Functions

fromList

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

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

fromListWith

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

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

fromListWith (++) [("A", [1]), ("A", [2]), ("B", [2]), ("B", [1]), ("A", [3])] == fromList [("A", [1, 2, 3]), ("B", [2, 1])]
fromListWith (++) [] == (empty : TextMap [Int])
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?

filterWithKey

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

merge

: (Text -> a -> Optional c) -> (Text -> b -> Optional c) -> (Text -> a -> b -> Optional c) -> TextMap a -> TextMap b -> TextMap c

Merge two maps. merge f g h x y applies f to all key/value pairs whose key only appears in x, g to all pairs whose key only appears in y and h to all pairs whose key appears in both x and y. In the end, all pairs yielding Some are collected as the result.

Module DA.Time

Data Types

data RelTime

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

instance Eq RelTime

instance Ord RelTime

instance Additive RelTime

instance Signed RelTime

instance Show RelTime

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.

instance Traversable TextMap

instance Traversable Optional

instance MapKey k => Traversable (Map k)

instance Traversable NonEmpty

instance Traversable (Either a)

instance Traversable ([])

instance Traversable a

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.

Module DA.Types

A module containing all the standard types from the base libraries, so they have nice names when used from Java or similar.

Data Types

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

Left a

Right b

instance (Eq a, Eq b) => Eq (Either a b)

instance (Ord a, Ord b) => Ord (Either a b)

instance (Show a, Show b) => Show (Either a b)

Module DA.Upgrade

Templates

template (Template i, Template o, Convertible o i) => Rollback i o

Field Type Description
op Party  
  • Choice External:Archive
  • Choice External:DoRollback

template (Template i, Template o, Convertible i o) => Upgrade i o

Field Type Description
op Party  
  • Choice External:Archive
  • Choice External:DoUpgrade

Typeclasses

class Convertible a b where

Types, for which there exists a conversion.

convert
: a -> b

class GenConvertible a b where

Generic representations that are isomorphic and have the same meta-data up to package id.

instance GenConvertible a1 a2 => GenConvertible a1 ((:*:) a2 (Opt b s))

instance (GenConvertible a1 a2, GenConvertible b1 b2) => GenConvertible ((:+:) a1 b1) ((:+:) a2 b2)

instance (GenConvertible a1 a2, GenConvertible b1 b2) => GenConvertible ((:*:) a1 b1) ((:*:) a2 b2)

instance GenConvertible a1 a2 => GenConvertible ((:*:) a1 (Opt b1 s)) a2

instance GenConvertible (K1 R c) (K1 R c)

instance GenConvertible c1 c2 => GenConvertible (K1 R (c1 x)) (K1 R (c2 x))

instance (Generic x repX, Generic y repY, GenConvertible repX repY) => GenConvertible (K1 R x) (K1 R y)

instance (MetaEquiv c1 c2, GenConvertible f1 f2) => GenConvertible (M1 i1 c1 f1) (M1 i2 c2 f2)

instance GenConvertible U1 U1

instance GenConvertible V1 V1

Functions

iso
: (Generic a repA, Generic b repB, Iso repA repB) => a -> b

Module DA.Validation

Validation type and associated functions.

Data Types

data Validation err a

A Validation represents eithor a non-empty list of errors, or a successful value. This generalizes Either to allow more than one error to be collected.

Errors (NonEmpty err)

Success a

instance Action (Validation err)

instance ActionFail (Validation Text)

instance Applicative (Validation err)

instance Functor (Validation err)

Functions

invalid

: err -> Validation err a

Fail for the given reason.

ok

: a -> Validation err a

Succeed with the given value.

validate

: Either err a -> Validation err a

Turn an Either into a Validation.

run

: Validation err a -> Either (NonEmpty err) a

Convert a Validation err a value into an Either, taking the non-empty list of errors as the left value.

run1

: Validation err a -> Either err a

Convert a Validation err a value into an Either, taking just the first error as the left value.

runWithDefault

: a -> Validation err a -> a

Run a Validation err a with a default value in case of errors.

(<?>)

: ActionFail m => Optional b -> Text -> m b

Convert an Optional t into a Validation Text t, or more generally into an m t for any ActionFail type m.

Module Data.String

Functions

fromString
: TextLit -> Text