-
Notifications
You must be signed in to change notification settings - Fork 52
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
Conversation
As per a discussion with @robrix at ICFP, we should expose this function to make the `NonDet` interface slightly less forbidding.
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.
Just the one question.
src/Control/Effect/NonDet.hs
Outdated
-- pure (a, b, c) | ||
-- @ | ||
choose :: (Foldable t, Alternative m) => t a -> m a | ||
choose = getAlt . foldMap (Alt . pure) |
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.
What do you think about doing foldMapA
instead? I personally find it much more generally useful, and it still enjoys good type inference properties.
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.
No objections at all to exposing foldMapA
as well as choose
.
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.
At that point, given that choose = foldMapA pure
, it seems like we don’t gain much from including both. Thoughts?
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’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.)
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, makes sense 👍
What do you think about renaming it to not conflict with #198’s smart constructor? Perhaps oneOf
?
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.
oneOf
is fine by me. choose
was a little too close to choice
from parsers
. Will make the change!
Regardless of whether we include |
choose
function to improve the ergonomics of NonDet.oneOf
function to improve the ergonomics of NonDet.
As per a discussion with @robrix at ICFP, we should expose this
function to make the
NonDet
interface slightly less forbidding.