Skip to content

Types

Types

Thagore is statically typed. Every binding has a known type by the end of type checking, either from an explicit annotation or from inference.

Primitive types

TypeSizeRange / semanticsDefault value
i3232-bit signed integer-2147483648 to 2147483647none; bindings must be initialized
i6464-bit signed integer64-bit signed integer rangenone; bindings must be initialized
f6464-bit IEEE floating pointdouble-precision floating pointnone; bindings must be initialized
boollogical booleantrue or falsenone; bindings must be initialized
strruntime-managed string handleimmutable string valuenone; bindings must be initialized
voidno valueused for functions that do not return a valueimplicit at function end
ptrraw pointer-like runtime valuelow-level interop and runtime APIsnone; bindings must be initialized

Thagore does not currently auto-initialize local variables. A declaration must either include a value or receive one before use.

Simple annotations

func main() -> i32:
let count: i32 = 42
let ratio: f64 = 3.5
let ok: bool = true
let name: str = "thagore"
return 0

Inference

You can omit the type when the initializer is enough:

func main() -> i32:
let count = 42
let ratio = 3.5
let label = "compiler"
return 0

Arrays

The type checker supports runtime arrays as Array[T] or Array<T>. In current code, arrays mostly enter the program through runtime-backed APIs such as std.io.read_ints.

func sum_items(items: Array[i32]) -> i32:
let total: i32 = 0
for item in items:
total = total + item
return total

Struct types

Structs are nominal types:

struct Point:
x: i32
y: i32
func sum(point: Point) -> i32:
return point.x + point.y

Generic type syntax

The AST and parser support generic type syntax with either angle brackets or legacy brackets:

func takes_vec(items: Vec<i32>) -> i32:
return 0
func takes_array(items: Array[i32]) -> i32:
return 0

Array[i32] is the currently exercised form in compiler tests and fixtures.

Conversion patterns

The language does not have a general cast operator today. Use stdlib helpers instead:

import std.string as string
func main():
let text = string.from_int(42)
println(text)
import std.string as string
func main() -> i32:
let value: i32 = string.to_int("42")
return value - 42
import std.string as string
func main():
println(string.from_f64(3.5))
println(string.from_bool(true))