Skip to content
Discussions/App Development/Airline Model - DAML CodeForum ↗

Airline Model - DAML Code

App Development6 posts459 views6 likesLast activity Apr 2022
ZE
ZerumOP
Mar 2022

Hi Team,

My name is Erum and I am still in learning phase of DAML. I have started an Airline Model example from DAML Repository

github.com

digital-asset/ex-models/blob/master/airline/daml/Airline.daml

-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE ApplicativeDo #-}
module Airline where

import DA.Assert
import DA.Optional
import DA.TextMap as TM
import Daml.Script

data Class = Coach | Business | First deriving (Eq, Show, Ord)

template FlightInvite
  with
    ticket : Ticket
  where
    signatory ticket.airline
    observer ticket.passenger

This file has been truncated. show original

My questions are:

  1. Is there any complete description of DAML code for Airline model as I want to understand the complete process to map it into UML Class diagram. I have gone through the readme file but it contains very little information to understand the complete model. I am trying to find an approach to communicate DAML code into business user so they can understand easily.

  2. In the following What is the seatClasses: TextMapClass attributes describes? and same for allocation: Text,Map Text. If you can explain me what are these attributes used for here?

template Flight
with
seatClasses : TextMap Class
allocation : TextMap Text
flightNumber : Text
airline : Party
invitedPassengers : [Party]
passengers : [Party]
where
signatory airline, passengers
observer invitedPassengers

Thank you

Regards
Erum

NE
nemanja
Mar 2022

Hi @Zerum and welcome to the Daml developer forum!

As far as I know there’s no more documentation around the Airline model than what’s in the GitHub repo. If you’re new to Daml I would recommend starting with @SteveSeow’s Daml 101 video series that will make reading the model easier.

Regarding your 2nd question: TextMap creates an associative array.

If you search for the seatClass argument of the template in the file you’ll find the following definition

    seatClasses = TM.fromList
      [ ("1A", First)
      , ("1B", First)
      , ("2A", Business)
      , ("2B", Business)
      , ("3A", Coach)
      , ("3B", Coach) ]

This assigns seat numbers to a ticket class.

The allocation attribute assigns a seat to an issued ticket

        create this with
          allocation = insert seat ticketRef allocation
ZE
Zerum
Mar 2022

Thank you for your reply. Very helpful for me. I am trying to find an approach to communicate DAML code into business user so they can understand easily. I am trying to map to code in UML Class Diagram. If I face problem later, I will come back to this forum again

Thank you so much

GA
Gary_Verhaegen
Mar 2022

Hi @Zerum,

I don’t personally think there is a good substitute for actually reading the code, and Daml has been designed to be relatively business-friendly in both syntax and semantics.

That being said, if we’re talking graphical representations, I should point out we do have a tool to generate diagrams from Daml code, which you may find useful.

ZE
Zerum
Apr 2022

Can you explain this
ticket.airline === flight.airline

Why there are 3 = signs used here?

A_
a_putkov
Apr 2022

@Zerum
When asking a new question, please always start a new thread.
To answer your question, this is an infix notation for the assetEq function, which checks if the values of two expressions are equal and fails with a message if they are not. Here’s the link to the documentation.

← Back to Discussions