Skip to content

Algebraic datatypes #303

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.

Activity

  1. peq commented on Jul 31, 2014

    @peq
    CollaboratorAuthor

    Of course, datatypes could also replace enums. So the language could get smaller 👍

  2. Cokemonkey11 commented on Aug 21, 2016

    @Cokemonkey11
    Collaborator

    I would use it. But what about standard library using options? we are already missing a lot of obvious stl functions and frequently PRs are a pain for user and maintainer.

    Option is super nice but it means that pretty much any STL extension function that uses a handle (unit, item, destructable especially) should have another override for Option, I think.

    I don't think this is more harm than good - I think it's nice. Just pointing it out.

  3. locked and limited conversation to collaborators on Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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