Skip to content

Type System

Type System

Thagore is statically typed. Types are checked at compile time. Every binding has a type either from an explicit annotation or from inference.

Primitive types

TypeDescriptionExample
i3232-bit signed integer42, -1, 0
i6464-bit signed integer1000000000
f6464-bit double-precision float3.14159
boolBoolean valuetrue, false
strRuntime-managed string"hello"
ptrRaw pointer-like runtime valueused in FFI
voidNo valueused in extern func return types

There is no f32 type available to user code. There is no String (uppercase) type — use lowercase str.

Type inference

Thagore infers types from initializer expressions:

func main() -> i32:
let x = 42 # i32
let y = 3.14 # f64
let name = "Alice" # str
let flag = true # bool
return 0

Explicit type annotations

Function parameters

func add(a: i32, b: i32) -> i32:
return a + b

Function return types

func greet(name: str) -> str:
return name

Struct fields

struct Point:
x: i32
y: i32

extern func declarations

extern func strlen(s: str) -> i32
extern func sqrt(x: f64) -> f64

Composite types

Structs

User-defined record types with named fields:

struct Rect:
width: i32
height: i32
func area(rect: Rect) -> i32:
return rect.width * rect.height

There is no struct constructor literal syntax. Structs enter the program through function parameters or runtime-backed APIs.

Arrays

The type Array[T] represents runtime arrays. Arrays are produced by runtime APIs; there are no array literals.

import std.io as io
func sum_items(items: Array[i32]) -> i32:
let total: i32 = 0
for item in items:
total = total + item
return total
func main() -> i32:
let values = io.read_ints(3)
return sum_items(values)

Fixed-size array types ([i32; 4]) and array indexing (arr[i]) are not implemented.

Generic functions

Functions can use type parameters with built-in constraints:

import std.math as math
func clamp_value(x: i32) -> i32:
return math.clamp(x, 0, 100)

Available constraints: Ordered, Eq, Numeric.

Type conversion

There is no general cast operator. Use stdlib helpers:

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

Features not in the current type system

FeatureStatus
enumnot implemented
matchnot implemented
type aliasnot implemented
trait / impl fornot implemented
fixed-size arrays [T; N]not implemented
array literalsnot implemented
struct constructor literalsnot implemented
f32 typenot available to user code