Type Inference
When a variable has an initial value, the compiler can automatically infer its type without explicit annotation. This makes code more concise while maintaining type safety.
Cangjie's inference rules are intuitive: integer literals default to Int64, floating-point literals infer as Float64, double-quoted strings infer as String, and true and false infer as Bool. Inference happens at the variable definition, based on the initial value's type.
The four variables in the code on the right have no explicit type annotations, yet the compiler accurately infers their types. Subsequent operations using these variables also depend on the inference results—the type of sum is inferred from x + 10. Try changing the initial value of x from 42 to 3.14 and observe what type error occurs with sum = x + 10.