Skip to content

Commit

Permalink
More Eq and Show instances
Browse files Browse the repository at this point in the history
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 an Eq instance 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!).

 * If the data type is extended to include a constructor with extra data
   attached to it, code that used == for state comparison may unintentionally
   perform content comparison.  However, this shouldn't be an issue if the user
   uses the form x == NullaryThing.
  • Loading branch information
joeyadams committed Apr 18, 2012
1 parent 3a101ea commit 25be09c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Database/PostgreSQL/LibPQ.hsc
Expand Up @@ -522,6 +522,7 @@ data TransactionStatus = TransIdle -- ^ currently idle
| TransInTrans -- ^ idle, in a valid transaction block
| TransInError -- ^ idle, in a failed transaction block
| TransUnknown -- ^ the connection is bad
deriving (Eq, Show)

-- | Returns the current in-transaction status of the server.
--
Expand Down Expand Up @@ -1055,6 +1056,8 @@ data FieldCode = DiagSeverity
-- ^ The name of the source-code function reporting the
-- error.

deriving (Eq, Show)


instance Enum FieldCode where
toEnum (#const PG_DIAG_SEVERITY) = DiagSeverity
Expand Down Expand Up @@ -1346,7 +1349,7 @@ data PrintOpt = PrintOpt {
, poTableOpt :: B.ByteString -- ^ attributes for HTML table element
, poCaption :: B.ByteString -- ^ HTML table caption
, poFieldName :: [B.ByteString] -- ^ list of replacement field names
}
} deriving Show


defaultPrintOpt :: PrintOpt
Expand Down Expand Up @@ -1536,6 +1539,7 @@ data CopyInResult
-- write-ready (e.g. by using
-- 'Control.Concurrent.threadWaitWrite'
-- on the 'socket') and try again.
deriving (Eq, Show)


toCopyInResult :: CInt -> CopyInResult
Expand Down Expand Up @@ -1584,6 +1588,7 @@ data CopyOutResult
| CopyOutError -- ^ An error occurred (e.g. the connection is
-- not in the 'CopyOut' state). Call
-- 'errorMessage' for more information.
deriving Show

-- | Receive raw @COPY@ data from the server during the 'CopyOut' state.
-- The boolean parameter determines whether or not the call will block
Expand Down Expand Up @@ -1817,6 +1822,7 @@ isnonblocking connection = enumFromConn connection c_PQisnonblocking
data FlushStatus = FlushOk
| FlushFailed
| FlushWriting
deriving (Eq, Show)

-- | Attempts to flush any queued output data to the server. Returns
-- 'FlushOk' if successful (or if the send queue is empty),
Expand Down Expand Up @@ -1910,7 +1916,7 @@ data Notify = Notify {
notifyRelname :: B.ByteString -- ^ notification channel name
, notifyBePid :: CPid -- ^ process ID of notifying server process
, notifyExtra :: B.ByteString -- ^ notification payload string
}
} deriving Show

instance Storable Notify where
sizeOf _ = #{size PGnotify}
Expand Down

0 comments on commit 25be09c

Please sign in to comment.