Custom Types
The following code examples demonstrate how custom types can be declared and used. See section [TBD] for details.
Type Declaration
`Declare a new type called "Special Int" to wrap around the built-in Int.`
`Default the value of this type to 0.`
Special Int: Int[0].`Declare a new type called "Some Record" to encapsulate
a couple of values as a single data type.`
Some Record:
{
Value A: Int[0];
Value B: Bool[false];
}.`Declare a new type called "Some Record" to encapsulate
a couple of values as a single data type and to fulfill the
contract "Valuable".`
Some Record [Valuable]:
{
Value A: Int[0];
Value B: Bool[false];
}.`Declare a new generic type called "Generic Record" to encapsulate
a couple of values as a single data type, including a value whose
type is generically defined as "TValue".`
Generic Record (TValue):
{
Generic Value: TValue;
Other Value: Bool[false];
}.Flags
`Declare a new type called "Constant Int" to define a constant
type for the value of 2.`
Constant Int: const Int[2].`Declare a new type called "Constant Record" to define a constant
type for an encapsulation of a couple of values that cannot be changed.`
Constant Record: const
{
Value A: Int[3];
Value B: Bool[true];
}.`Declare a new type called "Some Record" to define a data
type for an encapsulation of a couple of values, with a declared constant.`
Some Record:
{
Value A: Int[Constant A];
Value B: Bool[false];
},
Constant A: const Int[3].Decorators
With Identifiers
With Replacements
With Removals
With Identifiers
With Removals
With Replacements
With Identifiers
With Removals
With Replacements
Accessing
Setup
Retrieving
Setting
Operators
By default, a custom type that wraps an existing type inherits the operators of the existing type, including those of built-in types. Operators declared in the declaration of a type override any matching inherited operator.
As Variables
Basic types that wrap existing types have variables that are assigned/declared the same as the existing type's variables would be. Composite/Context types are assigned/declared as follows.
Assignment
Context-Only Assignment
Declaration
Context-Only Declarations
Last updated