Skip to content

Commit

Permalink
Use the new infix synonym for mappend (<>)
Browse files Browse the repository at this point in the history
Define it in Compat to support base < 4.5

Also, tweak Compat's doc comment, as we no longer use regex (see a2a04b3).
  • Loading branch information
joeyadams committed Jan 6, 2013
1 parent 9f69c5c commit e4f2e4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/Database/PostgreSQL/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ import Data.ByteString (ByteString)
import Data.Int (Int64)
import qualified Data.IntMap as IntMap
import Data.List (intersperse)
import Data.Monoid (mappend, mconcat)
import Data.Monoid (mconcat)
import Data.Typeable (Typeable)
import Database.PostgreSQL.Simple.BuiltinTypes ( oid2typname )
import Database.PostgreSQL.Simple.Compat ( mask )
import Database.PostgreSQL.Simple.Compat ( mask, (<>) )
import Database.PostgreSQL.Simple.FromField (ResultError(..))
import Database.PostgreSQL.Simple.FromRow (FromRow(..))
import Database.PostgreSQL.Simple.Ok
Expand Down Expand Up @@ -325,7 +325,7 @@ buildQuery conn q template xs = zipParams (split template) <$> mapM sub xs
sub (Many ys) = mconcat <$> mapM sub ys
split s = fromByteString h : if B.null t then [] else split (B.tail t)
where (h,t) = B.break (=='?') s
zipParams (t:ts) (p:ps) = t `mappend` p `mappend` zipParams ts ps
zipParams (t:ts) (p:ps) = t <> p <> zipParams ts ps
zipParams [t] [] = t
zipParams _ _ = fmtError (show (B.count '?' template) ++
" '?' characters, but " ++
Expand Down Expand Up @@ -499,8 +499,7 @@ doFold FoldOptions{..} conn _template q a f = do
where
go = do
-- FIXME: what about name clashes with already-declared cursors?
_ <- execute_ conn ("DECLARE fold NO SCROLL CURSOR FOR "
`mappend` q)
_ <- execute_ conn ("DECLARE fold NO SCROLL CURSOR FOR " <> q)
loop a `finally` execute_ conn "CLOSE fold"

-- FIXME: choose the Automatic chunkSize more intelligently
Expand Down
14 changes: 12 additions & 2 deletions src/Database/PostgreSQL/Simple/Compat.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{-# LANGUAGE CPP #-}
-- | This is a module of its own, because it uses the CPP extension, which
-- doesn't play well with the regex string literal in Simple.hs .
-- | This is a module of its own, partly because it uses the CPP extension,
-- which doesn't play well with backslash-broken string literals.
module Database.PostgreSQL.Simple.Compat
( mask
, (<>)
) where

import qualified Control.Exception as E
import Data.Monoid

-- | Like 'E.mask', but backported to base before version 4.3.0.
--
Expand All @@ -23,3 +25,11 @@ mask io = do
E.block $ io $ \m -> if b then m else E.unblock m
#endif
{-# INLINE mask #-}

#if !MIN_VERSION_base(4,5,0)
infixr 6 <>

(<>) :: Monoid m => m -> m -> m
(<>) = mappend
{-# INLINE (<>) #-}
#endif

0 comments on commit e4f2e4a

Please sign in to comment.