Structs
Numbat has compound data structures in the form of structs. A struct can be defined using the struct keyword, followed by the list of fields and their types. For example:
Structs can be instantiated by providing values for each field:
Fields can be accessed using dot notation:
let mass = 1 kg
let side_length = cbrt(mass / tungsten.density) -> cm
print("A tungsten cube with a mass of {mass} has a side length of {side_length:.2}.")
Generic structs
Structs can be generic over type parameters. Type parameters are declared in angle brackets after the struct name:
If you want to constrain a type parameter to be a dimension type, use the Dim bound: