DAML syntax - composition & key maintainer

Hi DAML鈥檈rs,

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鈥檚 the meaning of these:

  1. " maintainer key._1" ? ._1 means what?

  2. 鈥渃reate this with voters = voter::voters鈥 ? what鈥檚 the meaning of this 鈥::鈥 notation?

  3. 鈥淒A.Traversable.mapA (\voter 鈫 create DoodleInvite with doodleName = this.name, organizer = this.organizer, voter = voter) voters鈥

  4. 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

1 Like

Welcome to the forum @nr185!

Let me go through your questions in order:

  1. key._1 selects the first element of the tuple key. In your case, the key is a tuple of (organizer, voter, doodleName) so it will select the organizer. The reason for the slightly weird syntax as opposed to just writing organizer is that the maintainers need to be inferrable from just the key without the template argument.
  2. voter :: voters creates a list where the first element (head) is voter and the rest of the elements (tail) is voters. So it prepends a voter to the existing voters.
  3. 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. mapA is actually a bit more general than the type above and can be used for Script or even Optional and other effects.
  4. I don鈥檛 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?
3 Likes

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鈥檚 operational) and I will back to this forum soon, if I face a problem :slight_smile:

2 Likes

Maybe the visualization tool is worth a look to see if it helps with communication Visualizing Daml Contracts 鈥 Daml SDK 1.14.0 documentation

2 Likes

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 :slight_smile:

2 Likes

A post was merged into an existing topic: Must controllers be signatories?