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

Implement Maybe/Result with the built-in enum construct #133

Closed
gaku-sei opened this issue Jun 13, 2019 · 1 comment · Fixed by #139
Closed

Implement Maybe/Result with the built-in enum construct #133

gaku-sei opened this issue Jun 13, 2019 · 1 comment · Fixed by #139
Labels
help wanted Extra attention is needed

Comments

@gaku-sei
Copy link

Both Maybe and Result are implemented using the free JS construct: https://github.com/mint-lang/mint/blob/master/core/source/Maybe.mint#L4

The problem is, it's impossible to "pattern match" them:

case (maybeNumber) {
  Maybe::Nothing => ...
  Maybe::Just number => ...
}

Would lead to an error stating the Maybe enum doesn't exist.

Even though it's extremely easy to use Maybe.map and Maybe.withDefault to achieve this, it feels a bit inconsistent, and might be confusing for the newcomers (especially those with a accustomed to functional programming).

NB: Sorry for posting a lot of issues, I really like the language, and hope it can be better and better!

@gdotdesign gdotdesign added the help wanted Extra attention is needed label Jun 13, 2019
@gdotdesign
Copy link
Member

Maybe and Result are implemented this way because at the time there was no enum in the system 😄 so you are right and I'm planning to replace them with enums.

It's probably a nice exercise for someone to implement this 😉

  • Implement Maybe and Result using enums (tests in core should pass)
  • Replace every instance of new Just, new Nothing, new Ok, new Err with interpolations in the core *.mint files (tests in core should pass)
  • Always typecheck Maybe and mark them to always compile (I think Result is only needed when used while Maybe is used internally)
  • Replace every instance of new Just, new Nothing, new Ok, new Err in *.cr files by using their constructors (which is mangled)

NB: Sorry for posting a lot of issues, I really like the language, and hope it can be better and better!

No worries! Most of them I had in my head for a while but didn't create an issue for it so this is good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Development

Successfully merging a pull request may close this issue.

2 participants