DylanSp / faust-lang

An experimental language for exploring contract-based programming
MIT License
0 stars 0 forks source link

Prototype type system design for composing structs and sum types #15

Closed DylanSp closed 1 year ago

DylanSp commented 1 year ago

Issues include - can a struct be one case of a sum type?

Look what Rust does for inspiration.

DylanSp commented 1 year ago

Prior art from Rust

Sources:

Example enum:

enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(i32, i32, i32),
}

Pattern matching can destructure using field names. Example code:

match msg {
        Message::Move { x, y } => {
            println!("Move in the x direction {x} and in the y direction {y}");
        }
        // omitted - Quit, Write, ChangeColor cases
    }
DylanSp commented 1 year ago

Decisions for Faust

Type definitions:

Pattern matching: