You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
swagger2 makes use of a DeclareT monad transformer which lies between the WriterT and StateT.
It also provides an mtl-style MonadDeclare type class with some laws.
Since the construction is not specific to swagger2, it might make sense to add it to mtl and transformers.
The rationale for Declare is generating a list of Swagger schema definitions.
To avoid duplicates and to fix recursive schemas we need to look at the previous definitions.
But we don't want a full State because we don't want someone to accidentally erase/change all/some previous definitions in a ToSchema instance for a user data type.
The laziness plays nice part here and allows (mutually) recursive schemas to be written easily (e.g. see sources for declareSchemaRef).
Now, I see that the laws are carefully constructed such that this isn't a violation of any sort. But it does make me question the usefulness of those laws. When given an arbitrary MonadDeclare d m => m a, you have no idea if it behaves as a state monad or a declare monad, as it might wipe any declarations you make before using it. I imagine this should be seen as a problem?
I believe the laws are useful and although you made me doubt it, I still think they don't allow any MonadDeclare instance to erase output. However they probably might be better and/or clearer and I am open to suggestions!
Since AccumT is now in transformers, and #44 is an open issue, I am going to close this. Anyone feel free to re-open or ping to re-open if I'm missing something.
Activity
ElvishJerricco commentedon Jul 8, 2016
It is possible, when working directly in
DeclareT, to erase declared values.Now, I see that the laws are carefully constructed such that this isn't a violation of any sort. But it does make me question the usefulness of those laws. When given an arbitrary
MonadDeclare d m => m a, you have no idea if it behaves as a state monad or a declare monad, as it might wipe any declarations you make before using it. I imagine this should be seen as a problem?fizruk commentedon Jul 8, 2016
@ElvishJerricco I suspect you didn't actually run that in GHCi:
execDeclarereceives arguments in different order;DeclareT $ const $ return ([], ())is essentiallydeclare [];[1], as expected.Here's what I get:
I believe the laws are useful and although you made me doubt it, I still think they don't allow any
MonadDeclareinstance to erase output. However they probably might be better and/or clearer and I am open to suggestions!ElvishJerricco commentedon Jul 8, 2016
Oh geez you're right. That's what I get for browsing github issues on my phone =P My bad!
fizruk commentedon May 24, 2017
Starting with
transformers-0.5.4.0there'sControl.Monad.Trans.Accumwhich isDeclareTunder a different (more general) name —AccumT.chessai commentedon Jun 24, 2019
Since AccumT is now in transformers, and #44 is an open issue, I am going to close this. Anyone feel free to re-open or ping to re-open if I'm missing something.