Skip to content

Commit ed2041e

Browse files
authored
Make dhall -Wcompat clean (#331)
This fixes Dhall to exactly match the guidance given in https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid for compatibility with GHC 8.4
1 parent c87e5d9 commit ed2041e

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

dhall.cabal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Library
190190
Dhall.TypeCheck
191191
Other-Modules:
192192
Dhall.Pretty.Internal
193-
GHC-Options: -Wall
193+
GHC-Options: -Wall -Wcompat
194194

195195
Executable dhall
196196
Hs-Source-Dirs: dhall
@@ -204,7 +204,7 @@ Executable dhall
204204
prettyprinter-ansi-terminal >= 1.1.1 && < 1.2 ,
205205
trifecta >= 1.6 && < 1.8 ,
206206
text >= 0.11.1.0 && < 1.3
207-
GHC-Options: -Wall
207+
GHC-Options: -Wall -Wcompat
208208
Other-Modules:
209209
Paths_dhall
210210

@@ -222,7 +222,7 @@ Executable dhall-repl
222222
prettyprinter-ansi-terminal ,
223223
text ,
224224
trifecta
225-
GHC-Options: -Wall
225+
GHC-Options: -Wall -Wcompat
226226

227227
Executable dhall-format
228228
Hs-Source-Dirs: dhall-format
@@ -236,7 +236,7 @@ Executable dhall-format
236236
prettyprinter-ansi-terminal >= 1.1.1 && < 1.2 ,
237237
trifecta >= 1.6 && < 1.8 ,
238238
text >= 0.11.1.0 && < 1.3
239-
GHC-Options: -Wall
239+
GHC-Options: -Wall -Wcompat
240240
Other-Modules:
241241
Paths_dhall
242242

@@ -256,7 +256,7 @@ Test-Suite test
256256
Type: exitcode-stdio-1.0
257257
Hs-Source-Dirs: tests
258258
Main-Is: Tests.hs
259-
GHC-Options: -Wall
259+
GHC-Options: -Wall -Wcompat
260260
Other-Modules:
261261
Format
262262
Normalization

src/Dhall/Core.hs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ import Data.Bifunctor (Bifunctor(..))
5858
import Data.Foldable
5959
import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
6060
import Data.HashSet (HashSet)
61-
import Data.Monoid ((<>))
6261
import Data.String (IsString(..))
6362
import Data.Scientific (Scientific)
6463
import Data.Sequence (Seq, ViewL(..), ViewR(..))
64+
import Data.Semigroup (Semigroup(..))
6565
import Data.Text.Lazy (Text)
6666
import Data.Text.Lazy.Builder (Builder)
6767
import Data.Text.Prettyprint.Doc (Pretty)
@@ -468,20 +468,17 @@ instance IsString (Expr s a) where
468468
data Chunks s a = Chunks [(Builder, Expr s a)] Builder
469469
deriving (Functor, Foldable, Traversable, Show, Eq)
470470

471+
instance Data.Semigroup.Semigroup (Chunks s a) where
472+
Chunks xysL zL <> Chunks [] zR =
473+
Chunks xysL (zL <> zR)
474+
Chunks xysL zL <> Chunks ((x, y):xysR) zR =
475+
Chunks (xysL ++ (zL <> x, y):xysR) zR
476+
471477
instance Monoid (Chunks s a) where
472478
mempty = Chunks [] mempty
473479

474-
#if MIN_VERSION_base(4,11,0)
475-
instance Semigroup (Chunks s a) where
476-
(<>) (Chunks xysL zL) (Chunks [] zR) =
477-
Chunks xysL (zL <> zR)
478-
(<>) (Chunks xysL zL) (Chunks ((x, y):xysR) zR) =
479-
Chunks (xysL ++ (zL <> x, y):xysR) zR
480-
#else
481-
mappend (Chunks xysL zL) (Chunks [] zR) =
482-
Chunks xysL (zL <> zR)
483-
mappend (Chunks xysL zL) (Chunks ((x, y):xysR) zR) =
484-
Chunks (xysL ++ (zL <> x, y):xysR) zR
480+
#if !(MIN_VERSION_base(4,11,0))
481+
mappend = (<>)
485482
#endif
486483

487484
instance IsString (Chunks s a) where

src/Dhall/Parser.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE CPP #-}
1+
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DeriveDataTypeable #-}
33
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
44
{-# LANGUAGE OverloadedStrings #-}
@@ -26,8 +26,8 @@ import Control.Monad (MonadPlus)
2626
import Data.ByteString (ByteString)
2727
import Data.Functor (void)
2828
import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
29-
import Data.Monoid ((<>))
3029
import Data.Sequence (ViewL(..))
30+
import Data.Semigroup (Semigroup(..))
3131
import Data.Scientific (Scientific)
3232
import Data.String (IsString(..))
3333
import Data.Text.Lazy (Text)
@@ -95,14 +95,14 @@ newtype Parser a = Parser { unParser :: Text.Trifecta.Parser a }
9595
, MarkParsing Delta
9696
)
9797

98-
instance Monoid a => Monoid (Parser a) where
98+
instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Parser a) where
99+
(<>) = liftA2 (<>)
100+
101+
instance (Data.Semigroup.Semigroup a, Monoid a) => Monoid (Parser a) where
99102
mempty = pure mempty
100103

101-
#if MIN_VERSION_base(4,11,0)
102-
instance Semigroup a => Semigroup (Parser a) where
103-
(<>) = liftA2 (<>)
104-
#else
105-
mappend = liftA2 mappend
104+
#if !(MIN_VERSION_base(4,11,0))
105+
mappend = (<>)
106106
#endif
107107

108108
instance IsString a => IsString (Parser a) where
@@ -127,10 +127,10 @@ noted parser = do
127127
after <- Text.Trifecta.position
128128
return (Note (Src before after bytes) e)
129129

130-
count :: Monoid a => Int -> Parser a -> Parser a
130+
count :: (Semigroup a, Monoid a) => Int -> Parser a -> Parser a
131131
count n parser = mconcat (replicate n parser)
132132

133-
range :: Monoid a => Int -> Int -> Parser a -> Parser a
133+
range :: (Semigroup a, Monoid a) => Int -> Int -> Parser a -> Parser a
134134
range minimumBound maximumMatches parser =
135135
count minimumBound parser <> loop maximumMatches
136136
where

0 commit comments

Comments
 (0)