Proposal: Add an AnyTemplate to DAML and DAML-LF
See original GitHub issueThis 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 theAnyTemplate
type in DAML. - Add a
toAnyTemplate
builtin of type,a -> AnyTemplate
. The typechecker checks thata
is a template. We already have other primitives likecreate
that restrict a type to being a template. - Add a family of
fromAnyTemplate tyCon
builtins of typeAnyTemplate -> Optional a
that are parametrized by aTypeConName
. This primitive will check that the template wrapped inAnyTemplate
has the correspondingTypeConName
and if so unwrap it. During typechecking, we check that theTypeConName
corresponds toa
.
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:
- Created 4 years ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
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:
– 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.
👏 👏 👏