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

Add a oneOf function to improve the ergonomics of NonDet. #201

Merged
merged 6 commits into from
Sep 9, 2019

Conversation

patrickt
Copy link
Collaborator

As per a discussion with @robrix at ICFP, we should expose this
function to make the NonDet interface slightly less forbidding.

As per a discussion with @robrix at ICFP, we should expose this
function to make the `NonDet` interface slightly less forbidding.
@patrickt patrickt requested a review from robrix August 28, 2019 20:09
@robrix robrix mentioned this pull request Sep 3, 2019
2 tasks
Copy link
Contributor

@robrix robrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one question.

-- pure (a, b, c)
-- @
choose :: (Foldable t, Alternative m) => t a -> m a
choose = getAlt . foldMap (Alt . pure)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about doing foldMapA instead? I personally find it much more generally useful, and it still enjoys good type inference properties.

Copy link
Collaborator Author

@patrickt patrickt Sep 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections at all to exposing foldMapA as well as choose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At that point, given that choose = foldMapA pure, it seems like we don’t gain much from including both. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m a big fan of providing a single verb for “choose an element of this structure”, for a few reasons: both because I find existing foldMapA pure or asum . fmap pure patterns unreadable, or at best non-obvious, and also because I think this operation is extremely common. (I’ve been practicing some simple logic programs recently, and I needed choose in all of them.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense 👍

What do you think about renaming it to not conflict with #198’s smart constructor? Perhaps oneOf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oneOf is fine by me. choose was a little too close to choice from parsers. Will make the change!

@robrix
Copy link
Contributor

robrix commented Sep 8, 2019

Regardless of whether we include foldMapA or choose or both, we should add a note to the changelog 🙏

@patrickt patrickt changed the title Add a choose function to improve the ergonomics of NonDet. Add a oneOf function to improve the ergonomics of NonDet. Sep 9, 2019
@patrickt patrickt merged commit a1ad70a into master Sep 9, 2019
@patrickt patrickt deleted the add-choose branch September 9, 2019 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants