-
Notifications
You must be signed in to change notification settings - Fork 60
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
Make MonadDeclare more useful #100
Conversation
This makes the functions that generate schemas useful in more contexts. This could break clients that implements ToSchema if they somehow use Declare specifically, however most implementations should simply continue to compile (as all the instances here do).
New instances look great. Thanks! However, I'm not entirely sure that switching from @phadej can you advise on this? |
it's about the same as which one to pick I'd rather add and liftDeclare :: MonadDeclare d m => Declare d a -> m a
liftedDeclaredNamedSchema :: MonadDeclare (Definitions Schema) m => proxy a -> m NamedSchema and maybr a dependency on hoist :: (forall x. m x -> n x) -> DeclareT d m a -> DeclareT d n a for completeness |
I threw that change in mostly to get feedback, so thanks for jumping on it ;) In our project, where we’re using MonadDeclare constraints, I had to write this adapter: schemaRef :: (MonadDeclare (Definitions Schema) m, ToSchema a) => Proxy a -> m (Referenced Schema)
schemaRef = liftD . declareSchemaRef
where
liftD :: MonadDeclare d m => Declare d a -> m a
liftD da = do
(d', a) <- looks (runDeclare da)
declare d'
pure a If we were using the other functions that yield |
Thanks, @phadej. Guess I'd be happy with just adding |
Unrelatedly, the build is failing on ghc 7.8 because ExceptT is not available. Since I'm not using it, I’ll simply remove that instance. |
src/Data/Swagger/Declare.hs
Outdated
instance MonadDeclare d m => MonadDeclare d (ExceptT e m) where | ||
declare = lift . declare | ||
look = lift look | ||
-- Note: ExceptT not provided because it is not available in ghc 7.8. |
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.
You can use CPP like this:
#if __GLASGOW_HASKELL__ >= 710
instance MonadDeclare d m => MonadDeclare d (ExceptT e m) where
declare = lift . declare
look = lift look
#endif
I think I would rather drop instance for |
src/Data/Swagger/Declare.hs
Outdated
@@ -151,12 +154,11 @@ instance MonadDeclare d m => MonadDeclare d (ContT r m) where | |||
declare = lift . declare | |||
look = lift look | |||
|
|||
-- Note: deprecated, fails with -Wall | |||
instance (Error e, MonadDeclare d m) => MonadDeclare d (ErrorT e m) where | |||
#if __GLASGOW_HASKELL__ >= 710 |
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 should depend on transformers-compat >= 0.3
(if we don't), then ExceptT
will always be there.
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.
In Control.Monad.Trans.Except
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.
Right, I forgot about transformers-compat
.
And remove the #if for ghc 7.8
LGTM, Let's merge this when Travis is green. Adding |
Looks like there was already an (indirect) dependency on transformers-compat, but I suppose it is reasonable to make it explicit. Happy to add State and RWST. I just missed them because I happened to be looking at StateT's definition when I wrote mine. Thanks for all the detailed feedback, by the way! |
Perfect! Many thanks @mossprescott and @phadej! I'll make a release right away. |
Awesome. Thanks, @fizruk! |
Fixes #96.
The first commit adds instances for the standard transformers. Note: an instance is provided for
ErrorT
, which produces a deprecation warning when it's compiled.The second commit changes the types in Schema.hs to use
MonadDeclare
. Note: this changes the type ofdeclareNamedSchema
which may effect users of the library who provide instances ofToSchema
, so it may be considered a breaking change. However, I believe most reasonable implementations will continue to compile.