These are basic types that can be used to declare a variable.
bool
byte
char
float = f64
int = i32
str
Scientific types are usually used within programs dedicated to science, e.g. Math projects, Machine Learning projects, etc.
i8 u8
i16 u16
i32 u32
i64 u64
f32 f64
The Programming Language can automatically promote types.
For example:
fn expectI64 (num: i64) {
}
main {
intNum: int = 1
expectI64(intNum)
}
In this example variable intNum
will get automatically promoted to i64
type, when passed to expectI64
function.
There’s a table of all possible type promotions:
To | i8 | i16 | i32 | i64 | u8 | u16 | u32 | u64 | f32 | f64 |
---|---|---|---|---|---|---|---|---|---|---|
From i8 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ |
From i16 | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ |
From i32 | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ |
From i64 | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
From u8 | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
From u16 | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
From u32 | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ |
From u64 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ |
From f32 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ |
From f64 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
This type can hold only one character.
main {
ch := 'a'
}
Characters that can be escaped \n
, \f
, \r
, \t
, \v
, \e
, \0
, \'
,
\"
.
main {
ch1 := '\n'
ch2 := '\r'
ch3 := '\t'
}
This type can hold collection of characters.
main {
string := "Hello, World!"
}
Characters that can be escaped \n
, \f
, \r
, \t
, \v
, \e
, \0
, \'
,
\"
, \{
.
main {
text := "Some \n random \" text"
}
There are situation when you want to join two strings. To do this you need to
use +
operator.
main {
greet := "Hello, "
name := "World"
greeting := greet + name + "!"
}
You can find out more in arrays guide.
main {
arr := [1, 2, 3]
}
You can find out more in enumerations guide.
enum Color {
Red,
Green,
Blue
}
main {
color := Color.Red
}
You can find out more in functions guide.
main {
sum: (int, int) -> int
}
You can find out more in maps guide.
main {
mut a: str[str]
mut b: str[str] = {}
mut c := { "key": "value" }
}
You can find out more in objects guide.
obj Object {
a: int
b: str
}
main {
a: Object
b: Object = Object{}
c := Object{a: 1, b: "string"}
}
You can find out more in optionals guide.
main {
mut a: int?
mut b: int? = nil
mut c: int? = 1
}
You can find out more in references guide.
main {
a := 1
b := str
c: ref int = ref a
d := ref b
}
You can find out more in unions guide.
main {
mut a: int | str = 1
mut b: int | str = "test"
}
You can find out more in any guide.
main {
mut myVar: any
myVar = 1
myVar = 3.14
myVar = 'a'
myVar = "string"
}
This type can only be used as function return type.
fn printNumber (num: int) void {
print(num)
}
main {
printNumber(1)
}