8000 Type syntax design · Issue #84 · PistonDevelopers/dyon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Type syntax design #84
Closed
Closed
@bvssvni

Description

@bvssvni

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0