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

Implemented ADT (Algebraic Data Type) for enum #71

Merged
merged 11 commits into from
Aug 17, 2018
Merged

Implemented ADT (Algebraic Data Type) for enum #71

merged 11 commits into from
Aug 17, 2018

Conversation

gdotdesign
Copy link
Member

@gdotdesign gdotdesign commented Aug 12, 2018

This PR makes it possible parameterize enums and it's options and destructuring them in case statements.

Here is the Mint only implementation of the Result type as an Enum:

/* The enum has two parameters. */
enum Result(error, value) {
  Error(error)
  Ok(value)
}

module Result {
  fun withDefault(value : b, result : Result(a, b)) : b {
    case (result) {
      /* We can get values from options like this. */
      Result::Ok value => value
      Result::Error => value
    }
  }
}

This allows for better data modeling and creating better state machines.

@gdotdesign gdotdesign changed the title Implemented ADT (Abstract Data Type) for enum Implemented ADT (Algebraic Data Type) for enum Aug 12, 2018
@gdotdesign gdotdesign changed the base branch from master to development August 17, 2018 16:10
@gdotdesign gdotdesign merged commit 963d537 into development Aug 17, 2018
@gdotdesign gdotdesign deleted the adt branch August 26, 2018 08:18
@gdotdesign gdotdesign mentioned this pull request Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant