Type Annotation
Typed Let
let
statement may have type annotations.
let x: Int = 100;
cuminc
evaluates this in the following steps:
- eval
100
- the type infered as
Nat
because it is a (non-negative) natural number.
- the type infered as
- natural cast
x
is annotated asInt
.Nat
can be casted toInt
naturally.- get
100
asInt
.
- name it
x
In the natural cast, cuminc
doesn't coerce forcibly.
For example, String
to Int
, Int
to Nat
.
NOTE: If you need, as
-cast coerce to other types.
The type annotation is optional. If it is omitted, the step 2 will be skipped.
let x = 100;
In this example, x
is Nat
.
Typed Struct
In structs, all fields should be type annotated.
struct S {
x: Nat,
y: Int,
z: Array<String>,
}
When constructing struct values (applying), cuminc
checks the types of applied values.
S {
x = 1,
y = -2,
z = ["cumin"],
}