question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Add an AnyTemplate to DAML and DAML-LF

See original GitHub issue

This proposal describes an AnyTemplate type that I would like to see added to DAML and DAML-LF and the surrounding API. This is motivated by DAML Triggers where the trigger is passed a Create event with a field of type AnyTemplate that they can then safely convert to the original template type.

Changes to DAML

  • Add a new type AnyTemplate which corresponds to an existential template type.

Add a new type AnyTemplate to the standard library and extend the Template typeclass with the following 3 functions:

  • toAnyTemplate : Template t => t -> AnyTemplate
  • fromAnyTemplate : Template t => AnyTemplate -> Maybe t

Changes to DAML-LF

  • Add a new builtin type AnyTemplate type corresponding to the AnyTemplate type in DAML.
  • Add a toAnyTemplate builtin of type, a -> AnyTemplate. The typechecker checks that a is a template. We already have other primitives like create that restrict a type to being a template.
  • Add a family of fromAnyTemplate tyCon builtins of type AnyTemplate -> Optional a that are parametrized by a TypeConName. This primitive will check that the template wrapped in AnyTemplate has the corresponding TypeConName and if so unwrap it. During typechecking, we check that the TypeConName corresponds to a.

The builtins here will not technically be part of BuiltinFunction but will be separate AST nodes since BuiltinFunction is an Enum so we cannot have the TypeCon parameter here.

Questions/Design Decisions

Should the new types be serializable?

I wouldn’t make any of those types serializable at least initially. If we see usecases, we can relax it later. Relaxing restrictions is always easier than imposing them.

Implementation Plan

Given that this is a big missing piece for an MVP of DAML triggers and there are other efforts in DAML-LF land (e.g. Numeric and Map), I think it makes sense for the language team (primarily myself) to take over all of the implementation work here.

Pinging @hurryabit @associahedron @remyhaemmerle-da @gerolf-da as the LF maintainers and @bame-da for the DAML UX.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
cocreaturecommented, Sep 13, 2019

We get a family of builtins indexed by the template id that you convert to. So in the ast there is just a single case class but it has the template id as a parameter. This is similar to how create is represented.

Gerolf Seitz notifications@github.com schrieb am Fr., 13. Sep. 2019, 14:28:

Add a family of fromAnyTemplate tyCon builtins of type AnyTemplate -> Optional a that are parametrized by a TypeConName.

@cocreature https://github.com/cocreature: What does this “family of builtins” refer to? Is this more than one function?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/digital-asset/daml/issues/2876?email_source=notifications&email_token=AAKAWMA3MCKGYUOOQAKBUMLQJOBQPA5CNFSM4IVRZYJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6U34VI#issuecomment-531218005, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKAWMC7DWYIE53MUCC5JOTQJOBQPANCNFSM4IVRZYJQ .

– This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at  http://www.digitalasset.com/emaildisclaimer.html http://www.digitalasset.com/emaildisclaimer.html. If you are not the intended recipient, please delete this message.

0reactions
gerolf-dacommented, Sep 23, 2019

👏 👏 👏

Read more comments on GitHub >

github_iconTop Results From Across the Web

More about Contracts in DAML: Exploring Proposal ... - KC Tam
IOU Template for Propose-Accept Model. To achieve the proposal-acceptance model, we first modify the Iou template by adding owner as signatory, ...
Read more >
Generic Templates — DAML SDK 2019-11-07 documentation
Suppose we want to model a propose and accept workflow. This means that a party can propose a contract to a specific party,...
Read more >
Examples of Daml applications to help you get started quickly
On this page you can find all sorts of Daml sample applications to help you get started, learn about Daml features, or get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found