DAML syntax - composition & key maintainer
Hi DAML’ers,
My name is Nitia. I am still learning about DAML. I started with DAML in Doodle as an example (daml-examples/Doodle.daml at bff79195d6f685d2bc0299917db6eb294cf58c63 · entzik/daml-examples · GitHub).
There are 2 templates:
template Doodle
with
name: Text
organizer: Party
voters: [Party]
options: [Text]
votes: TextMap VotingSlot
open: Bool
where
signatory organizer
observer voters
ensure (unique voters) && (unique options)
key (organizer, name): (Party, Text)
maintainer (fst key)
template DoodleInvite
with
doodleName: Text
organizer: Party
voter: Party
where
signatory organizer
observer voter
key (organizer, voter, doodleName) : (Party, Party, Text)
maintainer key._1
My questions are What’s the meaning of these:
-
" maintainer key._1" ? ._1 means what?
-
“create this with voters = voter::voters” ? what’s the meaning of this “::” notation?
-
“DA.Traversable.mapA (\voter → create DoodleInvite with doodleName = this.name, organizer = this.organizer, voter = voter) voters”
-
As we know in UML class diagram concept that composition is when the class really depends on other class. It means that strong ownership. How to represent a strong ownership between template in DAML code?
Sorry for the basic questions. But I really want to learn about this.
Your answer would be very useful for me.
Thank you.
Best,
Nitia
Welcome to the forum @nr185!
Let me go through your questions in order:
-
key._1selects the first element of the tuplekey. In your case, the key is a tuple of(organizer, voter, doodleName)so it will select theorganizer. The reason for the slightly weird syntax as opposed to just writingorganizeris that the maintainers need to be inferrable from just the key without the template argument. -
voter :: voterscreates a list where the first element (head) isvoterand the rest of the elements (tail) isvoters. So it prepends a voter to the existing voters. -
mapA : (a -> Update b) -> [a] -> Update [b]allows you to apply an effectful function to each element in the list and get back the results. In this case, that effectful function creates a contract for each voter.mapAis actually a bit more general than the type above and can be used forScriptor evenOptionaland other effects. - I don’t think UML really translates to functional languages particularly well. Rather than asking how to represent UML terminology in DAML can you describe what underlying problem you are trying to solve?
Hi @cocreature !
Thank you for your reply. Very helpfull for me.
Yah sure, but I thought that I need to find an approach to communicate a DAML code into business user So they can understand easily.
But your suggestion also makes sense. I want to solve the optimization cash between branches (in bank’s operational) and I will back to this forum soon, if I face a problem 
Maybe the visualization tool is worth a look to see if it helps with communication Visualizing Daml Contracts — Daml SDK 1.14.0 documentation
Visualizing Daml Contracts — Daml SDK 1.14.0 documentation
Yes, thank you for the info. I already tried it. It looks like a call graph that describe the flow of choice call each other.
Thank you ![]()
A post was merged into an existing topic: Must controllers be signatories?