Types
The built-in types and type forms you use to describe values in Chic.
Built-in types
Chic is statically typed. Write a type after :, or use := to let the compiler infer it from the initializer.
| Type | Meaning |
|---|---|
i8, i16, i32, i64 | Signed integers, with 8, 16, 32, or 64 bits. |
u8, u16, u32, u64 | Unsigned integers of the same widths. |
byte | An unsigned 8-bit type, like u8. |
f32, float | 32-bit floating-point numbers. |
f64, double | 64-bit floating-point numbers. |
bool | A boolean value: true or false. |
char | An 8-bit character value. |
rune | A 32-bit Unicode code point; string iteration yields runes. |
string | A native UTF-8 pointer-and-length value. |
cstring | An alias for ^char, used with C strings. |
void | No return value; also used in untyped pointers such as ^void. |
TypeInfo, any, SourceLocation | Compiler-provided structures for type metadata, type-erased values, and source locations. |
Type names such as
i32 and string are built-in identifiers. The Keywords page lists reserved words separately.Declaring values
count : i32 = 42 // explicit type
name := "Chic" // inferred string
var index := 0 // mutable binding
Bindings are read-only by default. Add var when you need to assign a new value.
Use :: to declare a compile-time constant. Its value must be known at compile time. You can let Chic infer the type from the value, or specify the type before =.
| Form | Meaning |
|---|---|
<identifier> :: <value> | A compile-time constant with an inferred type. |
<identifier> :: <type> = <value> | A compile-time constant with an explicit type. |
BufferSize :: 4096 // inferred type
PacketLimit :: u16 = 65_535 // explicit type Composed types
| Form | Meaning |
|---|---|
^T | A pointer to a value of type T. |
[N]T | An array with fixed-size storage for N elements. |
[?]T | An array whose length is inferred from its initializer. |
[]T | A non-owning view over contiguous elements. |
[T, U] | A tuple containing multiple values. |
func(T) -> U | A callable function type. |
funcptr(T) -> U | A raw, context-free function pointer for native ABI boundaries. |
values : [3]i32 = {10, 20, 30}
view : []i32 = values[:]
pointer : ^i32 = &values[0]
text : string = "hello"
c_text : cstring = c"hello" User-defined types
Declare your own types with struct, enum, union, or raw_union. An alias gives an existing type another name.
alias UserId : i64
Point : struct {
x : f32 = 0
y : f32 = 0
}