Composite data types
Composite data types (CDTs) are used for storing more complex data in a structured composition in the memory.
Arrays
List ([N:t]T)
Growable array which allocated from heap to store T and the optional sentinel t, where t is T, with the minimum size of N.
Main := |_, _|
x := [1, 2, 3]
x := char['h', 'e', 'l', 'l', 'o']
end
Tuples ({})
An ordered set with finite size.
Declared using {T,V,..,N}
Main := |_, _|
coordinates := {74.5, 91.4}
end
Enums
Declared using '{} notation.
Enums are both tagged numbers and sum types.
Main := |_, _|
Base := '{
/* C++ - like tagged numbers */
Base2 i8 := 2
Base8 i8 := 8
Base16 i8 := 16
/* Aliasing (type of the right hand side will be used) */
Binary := Base.Base2
Octal := Base.Base8
Hexadecimal := Base.Base16
/* Sum types */
Other u8
}
myHex := Base.Hexadecimal
end
Records
Declared using #{} notation
Records are the data types to store data in a structured composition.
Main := |_, _|
Person := #{
name str
age u8
id any
faxNumber ?str
}
Vase(T) := #{ inner: T }
/*It's not necessary to state fields unless it is necessary to write in a specific order*/
Jan := {
"Jan"
20
"8675309"
nil
}
vaseOfi8 := Vase(i8){ 23 }
end
str
Declared using "" notation.
str is basically an immutable and internable []u8 and used for containing information in text with UTF-8 encoding.
Main := |_, _|
msg := "Hello, World!"
end