Chuchu is statically typed, but most local variables never mention a type. The value on the right of set already says what the variable is. Repeating it on the left would add a second place to change and a second place to get wrong.
set count to 10
set ratio to 0.5
set ready to true
show count
show ratio
show readyLocals follow the value
An integer literal infers i64, a decimal literal infers f64 and a boolean infers i1. Arrays are homogeneous and fixed-size, so [1, 2, 3] is an integer array and [1.0, 2.0] is a float array. The checker resolves the type once and then holds every reassignment to it.
That means set is a declaration with an inferred type, and reassign is a checked update. Assigning a float to an integer variable is an error, not a silent conversion. The compiler would rather stop than change the meaning of your arithmetic.
Signatures are contracts
Function parameters and return types are annotated. A signature is the part of a function other code depends on, so it stays visible at the definition and at every call site. It also lets Cheeku collect every function signature before checking any body, which is what makes forward calls, recursion and mutual recursion work.
function factorial(n: int) -> int {
if n <= 1 {
return 1
} else {
return n * factorial(n - 1)
}
}
show factorial(5)What inference does not do
- It does not coerce between integers and floats implicitly.
- It does not infer function parameter or return types.
- It does not make an array hold mixed element types.
- It does not defer errors to runtime: the program is checked before LLVM sees it.
The result is a language that stays quiet where the type is obvious and explicit where the contract matters. The type system chapter of the documentation has the full rules.