Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Let statements in templatesForum ↗

Let statements in templates

App Development4 posts661 views6 likesLast activity May 2020
LE
Leonid_RozenbergOP
May 2020

Although it isn’t documented (AFAIK), one can include lets inside of a template definition.

template Foo
  with
    sig : Party
    num : Int
  where
    let oneMore = num + 1
    signatory sig

    choice Incr : ContractId Foo
      controller sig
      do create Foo with num = oneMore, ..

this can be useful for common expressions in choices. Is this behavior that will be supported in the language or is it a bad idiom? Can we add it to the documentation?

BE
bernhard
May 2020

It’s actually something that took work to develop, not something that works incidentally due to GHC. It’s a shame we don’t document it. I’ll open a PR.

EDIT: Fixed in #5908

LE
Leonid_Rozenberg
May 2020

DAML feature discovery can be a game too; it would make for more exciting changelogs.

BE
bernhard
May 2020

Thanks to GHC, DAML has many, many undocumented features, but documenting them all would be information overload. My recommendation is that if you need something, find out whether Haskell does, it, and just try whether DAML also does it.

← Back to Discussions