Let statements in templates

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

template Foo
    sig : Party
    num : Int
    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?


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


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

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.