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

NonEmpty as a pure carrier for Choose. #250

Merged
merged 3 commits into from
Oct 7, 2019
Merged

Conversation

patrickt
Copy link
Collaborator

@patrickt patrickt commented Oct 6, 2019

In keeping with #206, this offers a solo Carrier instance for
NonEmpty lists over the Choose effects. Because NonEmpty is now
in base, this doesn't add new dependencies, and nicely rounds out
the carrier definition of [] for NonDet and Maybe for Empty.

In keeping with #206, this offers a solo `Carrier` instance for
`NonEmpty` lists over the `Choose` effects. Because `NonEmpty` is now
in `base`, this doesn't add new dependencies, and nicely rounds out
the carrier definition of `[]` for `NonDet` and `Maybe` for `Empty`.

-- | The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the 'eff' method.
class (HFunctor sig, Monad m) => Carrier sig m | m -> sig where
-- | Construct a value in the carrier for an effect signature (typically a sum of a handled effect and any remaining effects).
eff :: sig m a -> m a


instance Carrier Choose NonEmpty where
eff (Choose m) = m True S.<> m False
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The qualified import is the nicest way to handle the fact that GHC 8.2 doesn’t have <> in scope, without mucking up an import with #ifdef or causing warnings on other compiler versions.

Copy link
Contributor

@robrix robrix Oct 7, 2019

Choose a reason for hiding this comment

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

Could also say mappend for that purpose without the extra import, but I’m not particularly fussed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NonEmpty isn’t a Monoid!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh wait is mappend a synonym for <> now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh of course it isn’t! My bad.

@patrickt patrickt requested a review from robrix October 6, 2019 20:28

-- | The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the 'eff' method.
class (HFunctor sig, Monad m) => Carrier sig m | m -> sig where
-- | Construct a value in the carrier for an effect signature (typically a sum of a handled effect and any remaining effects).
eff :: sig m a -> m a


instance Carrier Choose NonEmpty where
eff (Choose m) = m True S.<> m False
Copy link
Contributor

@robrix robrix Oct 7, 2019

Choose a reason for hiding this comment

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

Could also say mappend for that purpose without the extra import, but I’m not particularly fussed.

@robrix robrix merged commit e762ee1 into master Oct 7, 2019
@robrix robrix deleted the choose-instance-for-nonempty branch October 7, 2019 13:40
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