Skip to content

Commit 253f1b9

Browse files
authored
Merge pull request #526 from bos/show-options-refac
Refactor and future proof Show Options instance
2 parents 88c244e + fd9ebd5 commit 253f1b9

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Data/Aeson/Types/Internal.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE DeriveDataTypeable #-}
33
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
44
{-# LANGUAGE Rank2Types #-}
5-
{-# LANGUAGE RecordWildCards #-}
65
#if __GLASGOW_HASKELL__ >= 800
76
-- a) THQ works on cross-compilers and unregisterised GHCs
87
-- b) may make compilation faster as no dynamic loading is ever needed (not sure about this)
@@ -75,6 +74,7 @@ import Data.Data (Data)
7574
import Data.Foldable (foldl')
7675
import Data.HashMap.Strict (HashMap)
7776
import Data.Hashable (Hashable(..))
77+
import Data.List (intercalate)
7878
import Data.Scientific (Scientific)
7979
import Data.Semigroup (Semigroup((<>)))
8080
import Data.String (IsString(..))
@@ -527,16 +527,17 @@ data Options = Options
527527
}
528528

529529
instance Show Options where
530-
show Options{..} = "Options {" ++
531-
"fieldLabelModifier =~ " ++
532-
show (fieldLabelModifier "exampleField") ++ ", " ++
533-
"constructorTagModifier =~ " ++
534-
show (constructorTagModifier "ExampleConstructor") ++ ", " ++
535-
"allNullaryToStringTag = " ++ show allNullaryToStringTag ++ ", " ++
536-
"omitNothingFields = " ++ show omitNothingFields ++ ", " ++
537-
"sumEncoding = " ++ show sumEncoding ++ ", " ++
538-
"unwrapUnaryRecords = " ++ show unwrapUnaryRecords ++
539-
"}"
530+
show (Options f c a o s u) =
531+
"Options {"
532+
++ intercalate ", "
533+
[ "fieldLabelModifier =~ " ++ show (f "exampleField")
534+
, "constructorTagModifier =~ " ++ show (c "ExampleConstructor")
535+
, "allNullaryToStringTag = " ++ show a
536+
, "omitNothingFields = " ++ show o
537+
, "sumEncoding = " ++ show s
538+
, "unwrapUnaryRecords = " ++ show u
539+
]
540+
++ "}"
540541

541542
-- | Specifies how to encode constructors of a sum datatype.
542543
data SumEncoding =

0 commit comments

Comments
 (0)