-
Notifications
You must be signed in to change notification settings - Fork 19
Show Maybe's "do notation" similarity to nested if-then-else statement #48
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
Conversation
src/Data/Maybe.purs
Outdated
-- | return x; // Nothing | ||
-- | } else { | ||
-- | var x' = x.unwrapJust; | ||
-- | var y = // ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since x
and y
are free variables in the first expression, I think they should probably be free variables in the pseudocode too. My main concern, though, would be that .isNothing
, .unwrapJust
, and wrapIntoJust
might not be clear enough: I'd guess the people who are able to work out what these functions/methods mean in this pseudocode are likely to be those who already understand what's going on anyway and don't need any additional explanation. I feel like it might be best to use prose rather than pseudocode here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I get that my editing for core library docs can be quite demanding, so I'm happy to take a stab at this myself if you'd prefer.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not using prose. Some examples, like this one, I think are easier to understand when you can see two code examples next to one another.
If you want to submit something, go for it!
I could also break down the bind
statements to this before showing the JavaScript version:
case x of
Nothing -> Nothing
Just x' -> case y of
Nothing -> Nothing
Just y' -> Just (f x' y')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s a really good point. Inlining everything so that it’s just pattern matching sounds great to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll update it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Just waiting for CI to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I was imagining that the pattern matching version would be instead of the pseudocode. I have to admit I'm sort of struggling to see the value of the pseudocode example in addition to the pattern matching version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm.... It has value for someone who is familiar with JavaScript or other C-family languages, who is still not yet comfortable with PureScript syntax.
Otherwise, I'm not sure it's needed anymore if they understand pattern matching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it in latest commit, so we can get this merged. We can always add it again later if people still have trouble with what's currently written.
No description provided.