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

Non-empty nondeterminism effect #198

Merged
merged 42 commits into from
Sep 18, 2019
Merged

Non-empty nondeterminism effect #198

merged 42 commits into from
Sep 18, 2019

Conversation

robrix
Copy link
Contributor

@robrix robrix commented Aug 25, 2019

This PR introduces a variant of NonDet which lacks Empty, and thus can only represent branching computations terminating successfully (or never terminating at all).

mfix f = ChooseC $ \ fork leaf ->
mfix (runChoose (liftA2 Fork) (pure . Leaf)
. f . fromJust . fold (<|>) Just)
>>= fold fork leaf
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like #197, this too suffers #209. I intend to fix this in a future PR (i.e. once I have any idea how to).


-- | 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))
Copy link
Contributor Author

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))

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! See below.

@robrix robrix marked this pull request as ready for review September 3, 2019 16:10
@robrix robrix changed the base branch from binary-nondet to master September 11, 2019 01:43
@robrix
Copy link
Contributor Author

robrix commented Sep 11, 2019

Ready for review ✨

@robrix
Copy link
Contributor Author

robrix commented Sep 12, 2019

I’ve added optional, many, some, and some1 now.

@patrickt
Copy link
Collaborator

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?

@robrix
Copy link
Contributor Author

robrix commented Sep 14, 2019

Since this now exports identifiers that could clash with Prelude-defined names

None of these names are exported by Prelude.

@robrix
Copy link
Contributor Author

robrix commented Sep 17, 2019

@patrickt: any objection to me merging given the above? ☝️

@robrix robrix merged commit 6d57670 into master Sep 18, 2019
@robrix robrix deleted the nonempty-nondet branch September 19, 2019 00:00
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.

Non-empty nondeterminism
2 participants