-
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
More transformers instances #366
Conversation
instance Algebra sig m => Algebra (Empty :+: sig) (Maybe.MaybeT m) where | ||
alg hdl sig ctx = case sig of | ||
L Empty -> Maybe.MaybeT (pure Nothing) | ||
R other -> Maybe.MaybeT $ thread (maybe (pure Nothing) Maybe.runMaybeT) hdl other (Just ctx) | ||
|
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 honestly don’t know why I didn’t implement this before.
newtype Swap s a = Swap { getSwap :: (a, s) } | ||
deriving (Functor) |
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.
This is handy for giving us a Functor
instance for the backwards pairs transformers
is so fond of.
#if MIN_VERSION_transformers(0,5,6) | ||
instance (Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (Writer.CPS.WriterT w m) where | ||
alg hdl sig ctx = case sig of | ||
L (Tell w) -> ctx <$ Writer.CPS.tell w | ||
L (Listen m) -> swapAndLift <$> Writer.CPS.listen (hdl (m <$ ctx)) | ||
L (Censor f m) -> Writer.CPS.censor f (hdl (m <$ ctx)) | ||
R other -> Writer.CPS.writerT $ getSwap <$> thread (\ (Swap (x, s)) -> Swap . fmap (mappend s) <$> Writer.CPS.runWriterT x) hdl other (Swap (ctx, mempty)) | ||
#endif |
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 had implemented this before, but removed it because it was unavailable on some of our ghc
s. But since we added CPP
to support the Ap
instance I figured I might as well add it back in.
This PR adds
Algebra
instances for a few more types fromtransformers
, namely including two only available in 0.5.6+.