Skip to content
Discussions/App Development/Why do I need to indent so much when constructing (not creating) a contract?Forum ↗

Why do I need to indent so much when constructing (not creating) a contract?

App Development3 posts422 views8 likesLast activity Jun 2020
SA
SamirTalwarOP
Jun 2020

Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.

I seem to need at least 5 spaces when indenting a with block in constructing a contract.

For example:

template Person
  with
    owner : Party
    name : Text
    dateOfBirth : Date
  where
    signatory owner

test = scenario do
  alice <- getParty "Alice"
  let person = Person with
        owner = alice
        name = "Alice"
        dateOfBirth = date 2020 Jan 1

  person.name === "Alice"

If I dedent the with block, so it looks like this:

  let person = Person with
      owner = alice
      name = "Alice"
      dateOfBirth = date 2020 Jan 1

Then I get the following error:

    • Constructor ‘Person’ does not have the required strict field(s): owner,
                                                                       name, dateOfBirth
    • In the expression: Person {}
      In an equation for ‘person’: person = Person {}

It appears as if the parser is recognizing nothing inside the with block.

If I go down to 2 spaces, I get an error on the first =:

    parse error on input ‘=’

Why do I need so much whitespace?

CO
cocreature
Jun 2020

You need to indent further than the name of the variable you are defining in your let. In

let person = Person with
    owner = alice

you are defining 2 let-bindings, person is bound to Person with (so no fields which is why you are getting the error) and owner is bound to alice.

SA
SamirTalwar
Jun 2020

Thanks @cocreature! I didn’t realize I could define multiple values in a single let.

← Back to Discussions