/ tests / tests / compiler / examples / message.adl
message.adl
 1  
 2  // This example demonstrates the definition and initialization of a "struct" in Leo.
 3  program test.alpha {
 4      // The "Message" struct.
 5      struct Message {
 6          // A struct member named "first" with type "field".
 7          first: field,
 8          // A struct member named "second" with type "field".
 9          second: field,
10      }
11  
12      // The "main" function of this Leo program takes a "Message" struct type as input.
13      // To see how to input variable "m" is passed in open up `inputs/message.in`.
14      transition main(m: Message) -> field {
15  
16          // 1. Define the "Message" type.
17          // 2. Use brackets `{ }` to enclose the struct members.
18          // 3. Define each struct member `name : value`.
19          let m1: Message = Message {
20              first: m.first,
21              second: m.second,
22          };
23  
24          // Access the members of a struct with dot syntax.
25          // `struct_name.member`
26          return m1.first + m1.second;
27      }
28  }