-
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
Non-empty nondeterminism effect #198
Conversation
mfix f = ChooseC $ \ fork leaf -> | ||
mfix (runChoose (liftA2 Fork) (pure . Leaf) | ||
. f . fromJust . fold (<|>) Just) | ||
>>= fold fork leaf |
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.
|
||
-- | Nondeterministically choose between two computations. | ||
choose :: (Carrier sig m, Member Choose sig) => m a -> m a -> m a | ||
choose a b = send (Choose (bool b a)) |
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 didn’t want to bring in a dependency on semigroupoids
(and all of the transitive dependencies it entails), or this might have been an Alt
instance (tho the n² instance problem would apply to that anyway).
NB: this name conflicts with #201, but I think we might want to generalize it to a foldMapA
function instead anyway.
-- | Nondeterministically choose between two computations. | ||
choose :: (Carrier sig m, Member Choose sig) => m a -> m a -> m a | ||
choose a b = send (Choose (bool b a)) | ||
|
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.
We could consider defining functionality like optional
against this interface, since it doesn’t require empty
. Likewise, possibly something like Data.List.NonEmpty.some1
.
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.
Done! See below.
Ready for review ✨ |
I’ve added |
Since this now exports identifiers that could clash with Prelude-defined names, should we indicate in the docs that users may want to import this module qualified? |
None of these names are exported by Prelude. |
@patrickt: any objection to me merging given the above? ☝️ |
This PR introduces a variant of
NonDet
which lacksEmpty
, and thus can only represent branching computations terminating successfully (or never terminating at all).