-
Notifications
You must be signed in to change notification settings - Fork 53
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
Conversation
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 |
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.
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.
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.
Could also say mappend
for that purpose without the extra import, but I’m not particularly fussed.
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.
NonEmpty isn’t a Monoid
!
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.
Oh wait is mappend
a synonym for <>
now?
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.
Oh of course it isn’t! My bad.
|
||
-- | 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 |
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.
Could also say mappend
for that purpose without the extra import, but I’m not particularly fussed.
In keeping with #206, this offers a solo
Carrier
instance forNonEmpty
lists over theChoose
effects. BecauseNonEmpty
is nowin
base
, this doesn't add new dependencies, and nicely rounds outthe carrier definition of
[]
forNonDet
andMaybe
forEmpty
.