Skip to content
CCPEDIAby Unity Nodes
App Development

DAML syntax - composition & key maintainer

5 posts535 views10 likesLast activity Jul 2021

  1. nr185OP 1

    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:

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

    2. “create this with voters = voter::voters” ? what’s the meaning of this “::” notation?

    3. “DA.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

  2. cocreature 3

    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’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?
  3. nr185 2

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

  4. cocreature 2

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

  5. nr185 2
    cocreature:

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