Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move NFData constraints to more sensible places.

  • Loading branch information...
commit 80d952eacb58ad6cf0f54b22394d4464a4c85578 1 parent 6260c7d
@bos authored
View
7 Database/MySQL/Simple.hs
@@ -80,17 +80,18 @@ finishExecute conn = do
then error "execute: executed a select!"
else Base.affectedRows conn
-query :: (QueryParams q, QueryResults r) => Connection -> Query -> q -> IO [r]
+query :: (QueryParams q, QueryResults r, NFData r)
+ => Connection -> Query -> q -> IO [r]
query conn template qs = do
Base.query conn =<< formatQuery conn template qs
finishQuery conn
-query_ :: (QueryResults r) => Connection -> Query -> IO [r]
+query_ :: (QueryResults r, NFData r) => Connection -> Query -> IO [r]
query_ conn (Query q) = do
Base.query conn q
finishQuery conn
-finishQuery :: (QueryResults r) => Connection -> IO [r]
+finishQuery :: (QueryResults r, NFData r) => Connection -> IO [r]
finishQuery conn = do
r <- Base.storeResult conn
ncols <- Base.fieldCount (Right r)
View
36 Database/MySQL/Simple/QueryResults.hs
@@ -14,7 +14,6 @@ module Database.MySQL.Simple.QueryResults
QueryResults(..)
) where
-import Control.DeepSeq (NFData(..))
import Control.Exception (throw)
import Data.ByteString (ByteString)
import Database.MySQL.Base.Types (Field)
@@ -22,54 +21,47 @@ import Database.MySQL.Simple.Result (ResultError(..), Result(..))
import Database.MySQL.Simple.Types (Only(..))
-- | A collection type that can be converted from a list of strings.
-class (NFData a) => QueryResults a where
+class QueryResults a where
convertResults :: [Field] -> [Maybe ByteString] -> a
-- ^ Convert values from a row into a Haskell collection.
--
-- This function will throw an exception if conversion of any
-- element of the collection fails.
-instance (NFData a, Result a) => QueryResults (Only a) where
+instance (Result a) => QueryResults (Only a) where
convertResults [fa] [va] = Only (convert fa va)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b,
- Result a, Result b) => QueryResults (a,b) where
+instance (Result a, Result b) => QueryResults (a,b) where
convertResults [fa,fb] [va,vb] = (convert fa va, convert fb vb)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c,
- Result a, Result b, Result c) => QueryResults (a,b,c) where
+instance (Result a, Result b, Result c) => QueryResults (a,b,c) where
convertResults [fa,fb,fc] [va,vb,vc] =
(convert fa va, convert fb vb, convert fc vc)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c, NFData d,
- Result a, Result b, Result c, Result d) =>
+instance (Result a, Result b, Result c, Result d) =>
QueryResults (a,b,c,d) where
convertResults [fa,fb,fc,fd] [va,vb,vc,vd] =
(convert fa va, convert fb vb, convert fc vc, convert fd vd)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c, NFData d, NFData e,
- Result a, Result b, Result c, Result d, Result e) =>
+instance (Result a, Result b, Result c, Result d, Result e) =>
QueryResults (a,b,c,d,e) where
convertResults [fa,fb,fc,fd,fe] [va,vb,vc,vd,ve] =
(convert fa va, convert fb vb, convert fc vc, convert fd vd,
convert fe ve)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
- Result a, Result b, Result c, Result d, Result e, Result f) =>
+instance (Result a, Result b, Result c, Result d, Result e, Result f) =>
QueryResults (a,b,c,d,e,f) where
convertResults [fa,fb,fc,fd,fe,ff] [va,vb,vc,vd,ve,vf] =
(convert fa va, convert fb vb, convert fc vc, convert fd vd,
convert fe ve, convert ff vf)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
- NFData g,
- Result a, Result b, Result c, Result d, Result e, Result f,
+instance (Result a, Result b, Result c, Result d, Result e, Result f,
Result g) =>
QueryResults (a,b,c,d,e,f,g) where
convertResults [fa,fb,fc,fd,fe,ff,fg] [va,vb,vc,vd,ve,vf,vg] =
@@ -77,9 +69,7 @@ instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
convert fe ve, convert ff vf, convert fg vg)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
- NFData g, NFData h,
- Result a, Result b, Result c, Result d, Result e, Result f,
+instance (Result a, Result b, Result c, Result d, Result e, Result f,
Result g, Result h) =>
QueryResults (a,b,c,d,e,f,g,h) where
convertResults [fa,fb,fc,fd,fe,ff,fg,fh] [va,vb,vc,vd,ve,vf,vg,vh] =
@@ -87,9 +77,7 @@ instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
convert fe ve, convert ff vf, convert fg vg, convert fh vh)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
- NFData g, NFData h, NFData i,
- Result a, Result b, Result c, Result d, Result e, Result f,
+instance (Result a, Result b, Result c, Result d, Result e, Result f,
Result g, Result h, Result i) =>
QueryResults (a,b,c,d,e,f,g,h,i) where
convertResults [fa,fb,fc,fd,fe,ff,fg,fh,fi] [va,vb,vc,vd,ve,vf,vg,vh,vi] =
@@ -98,9 +86,7 @@ instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
convert fi vi)
convertResults fs vs = convError fs vs
-instance (NFData a, NFData b, NFData c, NFData d, NFData e, NFData f,
- NFData g, NFData h, NFData i, NFData j,
- Result a, Result b, Result c, Result d, Result e, Result f,
+instance (Result a, Result b, Result c, Result d, Result e, Result f,
Result g, Result h, Result i, Result j) =>
QueryResults (a,b,c,d,e,f,g,h,i,j) where
convertResults [fa,fb,fc,fd,fe,ff,fg,fh,fi,fj]
View
3  Database/MySQL/Simple/Result.hs
@@ -20,7 +20,6 @@ module Database.MySQL.Simple.Result
#include "MachDeps.h"
import Control.Applicative ((<$>), (<*>), (<*), pure)
-import Control.DeepSeq (NFData)
import Control.Exception (Exception, throw)
import Data.Attoparsec.Char8 hiding (Result)
import Data.Bits ((.&.), (.|.), shiftL)
@@ -65,7 +64,7 @@ data ResultError = Incompatible { errSQLType :: String
instance Exception ResultError
-- | A type that may be converted from a SQL type.
-class (NFData a) => Result a where
+class Result a where
convert :: Field -> Maybe ByteString -> a
-- ^ Convert a SQL value to a Haskell value.
--
Please sign in to comment.
Something went wrong with that request. Please try again.