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
| Type | Description | Example |
|---|---|---|
i32 | 32-bit signed integer | 42, -1, 0 |
i64 | 64-bit signed integer | 1000000000 |
f64 | 64-bit double-precision float | 3.14159 |
bool | Boolean value | true, false |
str | Runtime-managed string | "hello" |
ptr | Raw pointer-like runtime value | used in FFI |
void | No value | used 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 0Explicit type annotations
Function parameters
func add(a: i32, b: i32) -> i32: return a + bFunction return types
func greet(name: str) -> str: return nameStruct fields
struct Point: x: i32 y: i32extern func declarations
extern func strlen(s: str) -> i32extern func sqrt(x: f64) -> f64Composite types
Structs
User-defined record types with named fields:
struct Rect: width: i32 height: i32
func area(rect: Rect) -> i32: return rect.width * rect.heightThere 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 0Features not in the current type system
| Feature | Status |
|---|---|
enum | not implemented |
match | not implemented |
type alias | not implemented |
trait / impl for | not implemented |
fixed-size arrays [T; N] | not implemented |
| array literals | not implemented |
| struct constructor literals | not implemented |
f32 type | not available to user code |