Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type syntax design #84

Closed
bvssvni opened this issue Mar 31, 2016 · 0 comments
Closed

Type syntax design #84

bvssvni opened this issue Mar 31, 2016 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Mar 31, 2016

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, except void)
  • 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
@bvssvni bvssvni changed the title Type syntax Type syntax design May 13, 2016
@bvssvni bvssvni closed this as completed May 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant