lpsmith/postgresql-libpq — pull request #4 by joeyadams (2012-04-18 06:58:40+00:00)
Title: Add more Eq and Show instances

Some data types missed the first wave of Eq, Show instance additions (commit 16a7b14), either because I overlooked them, or they were added recently. `Show` instances are really useful for testing stuff in GHCi. `Eq` instances make testing a result against a single expected value more convenient (e.g. `if status == PQ.ConnectionOk`).

The procedure I used to decide what types get Eq and Show instances is:

* If the data type is exported and has at least one data constructor:

* If it is purely an enumeration (no values attached to any data constructors), it gets an Eq instance. For example CopyOutResult is not given an Eq instance because the CopyOutRow constructor has a ByteString parameter.

* If its data constructors are exported, it gets a Show instance.

The decision to give result data types Eq instances is questionable. If the Eq instance is omitted, the user is forced to handle all cases exhaustively (which is good, especially if the API changes in the future!). However, I doubt the API will actually change much, and assuming users stick to comparisons of the form `x == NullaryThing` (and use case matching for more complex needs), the risk of API changes introducing bugs in peoples' code should be minimal. I went ahead and added the Eq instances.