Meetanshru
Meetanshru

Reputation: 35

How do I specify default values in DAML for primitive types and records?

I don't see a way to specify a default value in DAML. Say I want to specify False as the default value for a Bool or the time now as the default value for a variable of type Time. How do I do that?

Upvotes: 1

Views: 234

Answers (1)

cocreature
cocreature

Reputation: 811

DAML does not provide a way to specify default values. However, you can create functions that set the defaults, e.g., let’s say you have a template T:

template T 
  with
    p : Party
    value : Int
  where
    signatory p

You can now define a function createT that will set value to 42:

createT : Party -> T
createT p = T with
  p = p
  value = 42

You can then overide the default using with-syntax, e.g.

(createT alice) with value = 43

Upvotes: 3

Related Questions