Skip to content

Commit

Permalink
Use (<>) from Data.Monoid if compiler version is recent enough
Browse files Browse the repository at this point in the history
  • Loading branch information
saep committed Aug 27, 2015
1 parent 34208ff commit dd40c61
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Text/PrettyPrint/ANSI/Leijen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module Text.PrettyPrint.ANSI.Leijen (
-- * Character documents
lparen, rparen, langle, rangle, lbrace, rbrace, lbracket, rbracket,
squote, dquote, semi, colon, comma, space, dot, backslash, equals,

-- * Colorisation combinators
black, red, green, yellow, blue, magenta, cyan, white,
dullblack, dullred, dullgreen, dullyellow, dullblue, dullmagenta, dullcyan, dullwhite,
Expand All @@ -120,7 +120,7 @@ module Text.PrettyPrint.ANSI.Leijen (

-- * Emboldening combinators
bold, debold,

-- * Underlining combinators
underline, deunderline,

Expand Down Expand Up @@ -151,13 +151,17 @@ import System.Console.ANSI (Color(..), ColorIntensity(..), ConsoleLayer(..),

import Data.String (IsString(..))
import Data.Maybe (catMaybes)
#if __GLASGOW_HASKELL__ < 710
#if __GLASGOW_HASKELL__ >= 710
import Data.Monoid ((<>))
#elif __GLASGOW_HASKELL__ >= 704
import Data.Monoid (Monoid, mappend, mconcat, mempty, (<>))
#else
import Data.Monoid (Monoid, mappend, mconcat, mempty)
infixr 6 <>
#endif


infixr 6 <+>
infixr 5 </>,<//>,<$>,<$$>
infixr 6 <>,<+>


-----------------------------------------------------------
Expand Down Expand Up @@ -216,7 +220,7 @@ encloseSep left right sep ds
= case ds of
[] -> left <> right
[d] -> left <> d <> right
_ -> align (cat (zipWith (<>) (left : repeat sep) ds) <> right)
_ -> align (cat (zipWith (<>) (left : repeat sep) ds) <> right)


-----------------------------------------------------------
Expand Down Expand Up @@ -345,11 +349,13 @@ fold :: (Doc -> Doc -> Doc) -> [Doc] -> Doc
fold f [] = empty
fold f ds = foldr1 f ds

#if __GLASGOW_HASKELL__ < 704
-- | The document @(x \<\> y)@ concatenates document @x@ and document
-- @y@. It is an associative operation having 'empty' as a left and
-- right unit. (infixr 6)
(<>) :: Doc -> Doc -> Doc
x <> y = x `beside` y
#endif

-- | The document @(x \<+\> y)@ concatenates document @x@ and @y@ with a
-- @space@ in between. (infixr 6)
Expand Down Expand Up @@ -775,7 +781,7 @@ data SimpleDoc = SFail
-- from base gained a Monoid instance (<http://hackage.haskell.org/trac/ghc/ticket/4378>):
instance Monoid Doc where
mempty = empty
mappend = (<>)
mappend = beside
mconcat = hcat

-- MCB: also added when "pretty" got the corresponding instances:
Expand Down

0 comments on commit dd40c61

Please sign in to comment.