Types

Basic Types

These are basic types that can be used to declare a variable.

bool
byte
char
float = f64
int = i32
str

Scientific Types

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

Number Promotion

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

Char

This type can hold only one character.

main {
  ch := 'a'
}

Char Escaping

Characters that can be escaped \n, \f, \r, \t, \v, \e, \0, \', \".

main {
  ch1 := '\n'
  ch2 := '\r'
  ch3 := '\t'
}

String

This type can hold collection of characters.

main {
  string := "Hello, World!"
}

String Escaping

Characters that can be escaped \n, \f, \r, \t, \v, \e, \0, \', \", \{.

main {
  text := "Some \n random \" text"
}

String Concatenation

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 + "!"
}

Array

You can find out more in arrays guide.

main {
  arr := [1, 2, 3]
}

Enumeration

You can find out more in enumerations guide.

enum Color {
  Red,
  Green,
  Blue
}

main {
  color := Color.Red
}

Function

You can find out more in functions guide.

main {
  sum: (int, int) -> int
}

Map

You can find out more in maps guide.

main {
  mut a: str[str]
  mut b: str[str] = {}
  mut c := { "key": "value" }
}

Object

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"}
}

Optional

You can find out more in optionals guide.

main {
  mut a: int?
  mut b: int? = nil
  mut c: int? = 1
}

Reference

You can find out more in references guide.

main {
  a := 1
  b := str

  c: ref int = ref a
  d := ref b
}

Union

You can find out more in unions guide.

main {
  mut a: int | str = 1
  mut b: int | str = "test"
}

Any

You can find out more in any guide.

main {
  mut myVar: any

  myVar = 1
  myVar = 3.14
  myVar = 'a'
  myVar = "string"
}

Void

This type can only be used as function return type.

fn printNumber (num: int) void {
  print(num)
}

main {
  printNumber(1)
}