-
-
Notifications
You must be signed in to change notification settings - Fork 4
struct
A struct is a collection of primitives (int, string, ...) into a data tuple.
structs and named tuples
structs are instances of classes without the header in memory. Or put the other way round: classes are thin meta wrappers around structs. While the type information for struct instances is only available at compile time, the header of class instances is part of the data in memory.
Todo pass by reference or multi-value?
The wasp abi can return structs either as multi-value or as reference to days in linear memory
The struct
keyword in Angle is very similar to c and swift.
The main differences are: Meta information about all structs is stored in a custom type table, and or carried via return types. structs can be part of function dispatch, the only limitation being that they need to be determined at compile time, because unlike class instances, structs do not know their own type.
struct pointers as type schemes
multi-value returns allows to carry meta information about results in the form of smart pointers.
Each class has one corresponding raw type
corresponding to the struct definition of its fields.
? structs can contain non primitive values while classes can only contain reference types.
That is, in classes int is really resolved as type Integer (or int60?),
class example{
level:int
}
whereas in structs, int is really resolved as type int32
struct example{
level:int #int32
}
This internal distinction however is almost completely invisible to the developer.
Compare with NamedTuple(x: Int32, y: String) in ruby and record in C#