Closed
Description
Dyon uses an optional type system, one that complains if the types are proven to be wrong.
bool
(boolean)f64
(number)vec4
(4D vector)[]
/[T]
(array){}
(object)opt[T]
(option)res[T]
(result)thr[T]
(thread)any
- no syntax keyword - (any type, exceptvoid
)void
- no syntax keyword - (no value type)
Example
fn foo() -> opt[bool] {
return some(true)
}
fn main() {
if foo() {
println("oh?")
}
}
--- ERROR ---
In `source/test.rs`:
Type mismatch: Expected `bool`, found `opt[bool]`
6,8: if foo() {
6,8: ^
Any
An any
type works with any other type except void
.
Non-guarantee of argument type inside function body
Consider a simple example like this:
fn foo(a: bool) { ... }
It is not guaranteed that a
has the type bool
inside the function body. This is because the function can be called with an argument that is inferred to any
at type checking.
Motivation
These rules are designed for:
- Fast coding without having to fill out all the types
- Catch errors earlier when changing Rust/Dyon interface
- Backward compatible with old code when developing more advanced type checking later