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].
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
`Declare a new type called "Special Int" with modifiers to adjust its value.`
Special Int: Int[0],
reset this: () | this is 0;
update this with int: (i) | this is this + i.
`Declare a new type called "Special Int" with a modifier that adjusts
its value in accordance with an in-line mapping that has
conditional sub-mappings.`
Special Int: Int[0],
reset this: () |
this is this -> (Special Int => Special Int)
[
(i) ??
i % 2 = 1 => 1,
i = 0 => 0,
default => 2
].
`Declare a new type called "Some Record" with modifiers to adjust its values.`
Some Record:
{
Value A: Int[0];
Value B: Bool[false];
},
reset this: () |
this(Value A) is 0,
this(Value B) is false;
update this with Int: (i) |
this(Value A) is i,
this(Value B) is i > 10.
With Identifiers
Some Record:
{
Value A: Int[0];
Value B: Bool[false];
},
Reset :: reset this: () |
this(Value A) is 0,
this(Value B) is false;
Update :: update this with Int: (i) |
this(Value A) is i,
this(Value B) is i > 10.
With Replacements
Alias Record: Some Record,
refresh this: () replaces Reset |
reset this;
set this for Int: (i) replaces Update |
update this with i.
With Removals
Focused Record: Some Record,
!: replaces Reset;
!: replaces Update.
Accessing
Setup
`Assume the following for all accessing code examples.`
Record Name:
{
A: Int[-1];
B: Int[0];
}.
some record: Record Name, { B[2] };
Retrieving
some record (A) = -1
some record (A, B) = {-1, 2}
some record (...) = {-1, 2}
some record !(A) = 2
Setting
some record (A) is 2,
some record (A, B) is {1, ""},
some record (A, B) is other record (A, B),
some record (A, B) is other record (A[C], B[D]),
some record !(A) is { B[3] }, `Assign specific remaining values.`
some record (...) is matching record, `Assign all values.`
some record (...) is other record to Record Name, `Assign after mapping.`
some record (...) is {A[1], ...}, `Match remaining values.`
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
some record is {Value A [1], Value B [""]},
some record is {Value A [1], ...}, `Match (default) remaining values.`
Context-Only Assignment
mutualist context <= Host A is another context,
host context <= Mutualist A is another context,
Declaration
some record: Record Name; `Declare with all default values.`
some record: Generic Record Name(int); `Declare with all default values.`
some record: Record Name [ A[1], B[""] ]; `Default any unspecified values.`
some record: Generic Record Name(int) [ Generic A [1], NonGeneric A [""] ];
some record: Record Name [matching record];
some record: Record Name [matching context];
`Anonymous record composed of two unioned record types.`
some record: Record Name A + Record Name B [record A + record B];
some record: Record Name [other record to Record Name]; `Explicit mapping.`
Context-Only Declarations
mutualist context: Context Name [matching record] <= HostA is other context;
host context: Context Name [matching record] <= MutualistA is other context;
Last updated