on master help sign in
Merge pull request #526 from bos/show-options-refac

Refactor and future proof Show Options instance

commit253f1b98803b5536f33894711777d64fca43e2d0 authorAdam Bergmark <adam@bergmark.nl> dateSun 19 Mar 2017, 19:00 (10 years ago) parent88c244efd9ebd5
1 file changed+12−11
Data/Aeson/Types/Internal.hs+12−11
Data/Aeson/Types/Internal.hs+12−11
@@ -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)
7574import Data.Foldable (foldl')
7675import Data.HashMap.Strict (HashMap)
7776import Data.Hashable (Hashable(..))
77+import Data.List (intercalate)
7878import Data.Scientific (Scientific)
7979import Data.Semigroup (Semigroup((<>)))
8080import Data.String (IsString(..))
@@ -527,16 +527,17 @@ data Options = Options
527527 }
528528
529529instance 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.
542543data SumEncoding =