Types
Basic Types
Syntax: int, float, byte, char, string, bool, nothing
Notes:
inttype is a signed 8-byte integer data type.floatis double-precision 8-byte floating point number.byteis an unsigned 8-bit number.charis a single unicode character.Character literals should be enclosed in single-quote (e.g.
'a').
stringis a sequence of characters.String literals should be enclosed in double quotes.
To represent double quote itself inside a string, you can use
\".
booltype is same as int but with only two valid values.trueis 1 andfalseis 0.nothingis a special type which is used to denote empty/invalid/missing data. This type has only one value which is the same identifier.
Examples
int_val = 12
float_val = 1.918
char_val = 'c'
bool_val = true
str1 = "Hello world!"
str2 = "Hello" + "World!"
n: nothing = nothing
#note that it is optional to mention type of a binding after its name
byte_val: byte = 119 Sequence
Sequence is similar to array in other languages. It represents a fixed-size block of memory with elements of the same type,
T, and is shows with[T]notation.You can initialise a sequence with a sequence literal (First example).
You refer to elements inside sequence using
x[i]notation whereiis index number.[]represents an empty sequence.Referring to an index outside sequence will throw a runtime error.
Core defines built-in functions for sequence for common operations:
slice, map, reduce, filter, anyMatch, allMatch, ...
Examples
Map
HashMap is a hash table of key values.
You can use
[KeyType:ValueType]to define a map type.When reading from a map, you will get runtime error if value does not exist in the map.
An empty map can be denoted using
[:]notation.Core defines built-in functions for maps for common operations:
slice, map, reduce, filter, hasKey, anyMatch, allMatch, ...
Examples
Enum
You can prefix any sequence literal with
enumkeyword and it will be an enum type.Example:
MyEnumType = enum [sequence of literals]Variables of enum type must accept values of exactly what is specified inside the sequence, nothing else, even if they have equivalent value.
You can combine enum with a map to implement execution control.
In case of 4, Compiler will make sure you have covered all possible types, and if not, will issue a warning.
Also core will have functions to implement
switchon enums which make sure all cases are covered.
Examples
Union
Bindings of union type, can store any of multiple pre-defined types.
Union type are shown as
T1|T2|T3|....You can use casting to check what's inside a union binding or cast it to a type.
For union, you can use casting to get underlying type. If you cast a union binding to a wrong type, there will be a runtime error.
You can cast a union to
T|nothingto do a safe cast. You will getnothingit type T is not inside the union binding.
Examples
Struct
A struct, similar to C, represents a set of related named types.
To create a binding based on a struct, you should use a struct literal (e.g.
Type{field1:value1, field2:value2, ...}.Optional fields: When creating a value of struct type and don't specify value for fields which can be
nothing, they will be set tonothing.Edit: You can create a new struct value based an existing value. This will merge them all. (Example A).
If struct literal type can be inferred from context, you can omit type and use
&{...}notation (Example B).
Examples
Last updated
Was this helpful?