Remove the transformers dependency - #42
Merged
Merged
Conversation
Kleisli m a is a newtype over `a -> m b`, so two nested Kleislis have exactly this parser's shape, and their Applicative and Alternative instances are the same pointwise lifting of Maybe that ReaderT provides. Kleisli lives in base, so this drops the only use of transformers in Hpgsql.Msgs while keeping both instances lawful by construction.
Both connection string parsers ran in `ExceptT String Identity`, which is isomorphic to `Either String` - the type they already returned. Using Either directly removes the last use of transformers in the library, so the dependency goes away. Behavior is unchanged: ExceptT's bind and applicative short-circuit on the first error exactly like Either's.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the discussion in #34.
Two changes, one per commit:
Hpgsql.Msgs: derivePgMsgParser'sApplicative/AlternativeviaKleisli (Kleisli Maybe LBS.ByteString) Charinstead ofReaderT.Kleisliis thea -> m bnewtype from base, and its instances are the same pointwise lift intoMaybethatReaderTprovides, so the instances stay lawful by construction.Hpgsql.Connection: both connection string parsers ran inExceptT String Identity, which is isomorphic to theEither Stringthey already return. UsingEitherdirectly removes the last use oftransformers, so the dependency is dropped frombuild-depends.Behavior is unchanged in both cases:
Kleisli's<|>keepsMaybe's left bias (and carries the same INLINE pragmaReaderT's does), andExceptT's bind and applicative short-circuit on the first error exactly likeEither's.Verified with
nix-build -A hpgsqlon ghc967, ghc984, ghc9103 and ghc9122, and-A testsPg18/-A hpgsqlSimpleCompatTestsPg18-133 examples, 0 failures, including the
LibPqConnStringParsingSpecyou added in #41, which covers the parsers this touches. hlint and fourmolu are clean.