Skip to content

Algebraic datatypes #303

@peq

Description

@peq

Just an idea.

Datatypes would be a generalization of tuples. Nonrecursive datatypes would be translated similar to tuples. Recursive datatypes would be translated similar to classes, but with some kind of reference counting to have automated deallocation. This is possible, because immutable datatypes cannot have cycles, and because datatypes will not be castable to int.

Some examples:

// could replace tuples:
data vec2 = vec2(real x, real y)
// can be generic and have cases:
data option<A> = Some(A a) | None
// can be recursive
data list<A> = Cons(A head, list<A> tail) | Nil

Discuss.

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