Skip to content

Remove the transformers dependency - #42

Merged
mzabani merged 2 commits into
mzabani:masterfrom
comonoid:drop-transformers
Aug 1, 2026
Merged

Remove the transformers dependency#42
mzabani merged 2 commits into
mzabani:masterfrom
comonoid:drop-transformers

Conversation

@comonoid

@comonoid comonoid commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the discussion in #34.

Two changes, one per commit:

  • Hpgsql.Msgs: derive PgMsgParser's Applicative/Alternative via Kleisli (Kleisli Maybe LBS.ByteString) Char instead of ReaderT. Kleisli is the a -> m b newtype from base, and its instances are the same pointwise lift into Maybe that ReaderT provides, so the instances stay lawful by construction.
  • Hpgsql.Connection: both connection string parsers ran in ExceptT String Identity, which is isomorphic to the Either String they already return. Using Either directly removes the last use of transformers, so the dependency is dropped from build-depends.

Behavior is unchanged in both cases: Kleisli's <|> keeps Maybe's left bias (and carries the same INLINE pragma ReaderT's does), and ExceptT's bind and applicative short-circuit on the first error exactly like Either's.

Verified with nix-build -A hpgsql on ghc967, ghc984, ghc9103 and ghc9122, and -A testsPg18 / -A hpgsqlSimpleCompatTestsPg18 -
133 examples, 0 failures, including the LibPqConnStringParsingSpec you added in #41, which covers the parsers this touches. hlint and fourmolu are clean.

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.

@mzabani mzabani left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you once again :)

@mzabani
mzabani merged commit 47d43b0 into mzabani:master Aug 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants