Writing Types
Also known as: type annotation type inference type hints signature
● Intermediate3 minSpec 2.10
Types are written where people read them: parameters, results and record fields. Everywhere else they are worked out.
| Local variables | worked out |
| Lambda parameters and results | worked out |
| Function parameters | written |
| A function's result | written |
| Record fields | written |
fn double(x) -> Int {
x * 2
}
fn main() {
print(double(4))
}The compiler refused the program:
kavach run untyped-param.kav
error: write the type of `x`: parameters always have a typeA signature is what people, and AI tools, read to know a function. So it is always spelled out, even for a private function; inside the body, the compiler works everything out.