Conjure is a statically typed language with all types being known at compile time. This ensures type safety and allows for optimizations during compilation.
Type Inference
Conjure supports type inference for variable declarations and expressions. When you declare a variable without an explicit type, Conjure infers the type based on the assigned value.
var w = true // inferred as bool
var x = 42 // inferred as u8
var y = 3.14 // inferred as f32
var z = "Hello" // inferred as stringType Conversions
Conjure supports implicit type promotion during arithmetic operations to the largest type involved, so long as the interpretation of the value remains unchanged. Literal values are also implicitly promoted to the target type when assigned to a variable.
If the result cannot fit in the target type, a warning will be issued (though this may change to an error in the future). You can suppress these warnings with explicit casts. This means you’ll almost always need to use explicit casts when converting floating-point values to integers.
var x i32 = 42
var y i64 = i64(x) // explicit conversion (up) to i64
var z f32 = f32(x) // explicit conversion to f32
var large i64 = 1000000
var small i32 = i32(large) // truncates if value doesn't fitZero Values
All types in Conjure have a zero value that they’re initialized to if you don’t provide an explicit value. In the case of structs, all fields are recursively initialized to their zero values.
| Type | Zero Value |
|---|---|
| Integer types | 0 |
| Floating-point types | 0.0 |
bool | false |
char | '\0' (null character) |
string | "" (empty string) |
| Pointers | null |
| Structs | All fields set to their zero values |
var count i32 // automatically initialized to 0
var flag bool // automatically initialized to falseSize and Alignment
You can query the size and alignment requirements of any type using the type reflection API. Alignment can be accessed via the .align property, while size can be accessed via the .size property. These are compile-time constants and can be used in constant expressions.
var size = i32.size // returns 4
var align = i64.align // returns 8