Data structures
The only way to build data structures in Opa is to use records, which we will talk about later on. All other data structures, such as tuples and lists, are based on records. Opa provides different modules to help the user to manipulate lists and maps. Let's first have a look at records.
Records
Simply speaking, a record is a collection of data. Here is how to build a record:
x = {} // the empty record x = {a:2,b:3} //a record with field "a" and "b"
The empty record,{}
, has a synonym, void
, which means the same thing. There are a number of syntactic shortcuts available to write records concisely. First, if you give a field name without the field value, it means the value of this field is void
:
x = {a} // means {a:void} x = {a, b:2} // means {a:void b:2}
The second shorthand we always use is the sign ~
. It means if the field value is left empty, assign it with a variable having the same name as the field name:
x = {~a, b:2} // means {a:a, b:2} x = ~{a, b} // means {a...