cumin
cumin copied to clipboard
[Feature] If-statement
To implement (type-safe) If-statement, the followings may need.
- Type inferred functions.
- Functions have types of arguments, but don't know the type of output.
- To investigate the type without concrete argument values, type-infer needs instead of
eval
.- Since latest cumin doesn't have loop or recursion, this is trivial.
fn f(x: Int) = [x]; // inferred as `Int -> Array<Int>`
// OK
fn g(x: Int) = { // inferred as `Int -> Array<Int>`
if x == 0 {
[]
} else {
f(x)
}
};
// NG
fn h(x: Int) = {
if x == 0 {
0
} else {
f(x) // this doesn't match to `0`.
}
};
// NG
fn i(x: Int) = {
if true {
0
} else {
[x]
} // this is always (0: Int), but this is invalid.
};