Skip to content

Derive lawful Applicative and Alternative for PgMsgParser#34

Open
comonoid wants to merge 1 commit into
mzabani:masterfrom
comonoid:pgmsgparser-deriving-via
Open

Derive lawful Applicative and Alternative for PgMsgParser#34
comonoid wants to merge 1 commit into
mzabani:masterfrom
comonoid:pgmsgparser-deriving-via

Conversation

@comonoid

@comonoid comonoid commented Jul 7, 2026

Copy link
Copy Markdown

This removes the
TODO: Is this Applicative correct? Double-check laws in Hpgsql.Msgs

Behavior is unchanged: the derived methods coerce to
the same functions the manual instances defined.
One note for reviewers: ReaderT must be imported
with its constructor (ReaderT (..)) for GHC to build the coercion.

No new dependencies — transformers was already a direct dependency.
Tested with run tests (131 examples, 0 failures) and run format-hs; hlint has no hints.

The hand-written instances were the pointwise lifting of Maybe through
two readers, which is exactly what ReaderT Char (ReaderT LBS.ByteString Maybe)
provides. Deriving via that type makes the instances lawful by
construction and removes the TODO questioning the Applicative laws.
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.

1 participant