You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
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 👍
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:
Would lead to an error stating the
Maybe
enum doesn't exist.Even though it's extremely easy to use
Maybe.map
andMaybe.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!
The text was updated successfully, but these errors were encountered: