on master help sign in
Merge pull request #458 from bos/pre-1.0.0.0

final 1.0.0.0 touch ups

commitdaba490fac344e6ff98d902bb2f8250a9b77bd4b authorAdam Bergmark <adam@bergmark.nl> dateSun 7 Aug 2016, 13:36 (10 years ago) parentc8037e314a5d59
66 files changed+864−599
CONTRIBUTING.md+46 Data/Aeson.hs+2−4 Data/Aeson/Encode.hs+4−2 Data/Aeson/Encoding.hs+3−1 Data/Aeson/Encoding/Builder.hs+3−1 Data/Aeson/Encoding/Internal.hs+14−17 Data/Aeson/Internal.hs+2 Data/Aeson/Internal/Functions.hs+2−1 Data/Aeson/Parser.hs+3−3 Data/Aeson/Parser/Internal.hs+4−3 Data/Aeson/Parser/Time.hs+3−2 Data/Aeson/TH.hs+38−58 Data/Aeson/Text.hs+8−4 Data/Aeson/Types.hs+1−2 Data/Aeson/Types/Class.hs+3−1 Data/Aeson/Types/FromJSON.hs+68−73 Data/Aeson/Types/Generic.hs+21−10 Data/Aeson/Types/Internal.hs+8−5 Data/Aeson/Types/ToJSON.hs+242−239 aeson.cabal+11−1 benchmarks/AesonCompareAutoInstances.hs+12−14 benchmarks/AesonEncode.hs+9−2 benchmarks/AesonFoldable.hs+9−4 benchmarks/AesonMap.hs+15−7 benchmarks/AesonParse.hs+8−2 benchmarks/AesonTuples.hs+5−2 benchmarks/Compare.hs+5−2 benchmarks/Compare/BufferBuilder.hs+9−3 benchmarks/Compare/JsonBench.hs+8−2 benchmarks/Compare/JsonBuilder.hs+6−1 benchmarks/CompareWithJSON.hs+6−1 benchmarks/Dates.hs+5−1 benchmarks/JsonParse.hs+8−2 benchmarks/Micro.hs+3−1 benchmarks/Options.hs+4−1 benchmarks/ReadFile.hs+7−1 benchmarks/Typed.hs+3 benchmarks/Typed/Common.hs+12−6 benchmarks/Typed/Generic.hs+4−3 benchmarks/Typed/Manual.hs+4−3 benchmarks/Typed/TH.hs+4−4 benchmarks/aeson-benchmarks.cabal+11−1 changelog.md+51−25 examples/Generic.hs+7−5 examples/Simplest.hs+8−2 examples/TemplateHaskell.hs+6−3 examples/Twitter.hs+9−5 examples/Twitter/Generic.hs+5−2 examples/Twitter/Manual.hs+11−6 examples/Twitter/TH.hs+5−1 examples/aeson-examples.cabal+3 stack.yaml → stack-lts6.yaml+4−1 stack-nightly.yaml+12 tests/DataFamilies/Encoders.hs+4−1 tests/DataFamilies/Instances.hs+4−3 tests/DataFamilies/Properties.hs+3−1 tests/DataFamilies/Types.hs+4−1 tests/Encoders.hs+3 tests/Functions.hs+8−1 tests/Instances.hs+13−14 tests/Options.hs+3 tests/Properties.hs+13−13 tests/Tests.hs+3 tests/Types.hs+6−3 tests/UnitTests.hs+28−20 tests/UnitTests/NullaryConstructors.hs+8−2
CONTRIBUTING.mdnew file+46
@@ -0,0 +1,46 @@
1+# Style guide
2+
3+* 4 space indentation
4+
5+## Pragmas
6+
7+* One pragma on each line
8+* No alignment
9+* Sort lexicographically
10+
11+```haskell
12+{-# LANGUAGE BangPatterns #-}
13+{-# LANGUAGE CPP #-}
14+{-# LANGUAGE DataKinds #-}
15+```
16+
17+## Module declaration and exports
18+
19+* Opening paren on its own line
20+* Prefix with commas
21+* End with `) where`
22+
23+```haskell
24+module Data.Aeson.Types.ToJSON
25+ (
26+ -- * Core JSON classes
27+ ToJSON(..)
28+ -- * Liftings to unary and binary type constructors
29+ , ToJSON1(..)
30+ , toJSON1
31+ ) where
32+```
33+
34+## Imports
35+
36+* No alignment of import lists or qualifications
37+* Sort lexicographically (qualified imports will be last)
38+* No space between types and constructor lists
39+* Sort identifiers in import lists lexicographically
40+
41+```haskell
42+import BarBar as B ((<>), foo)
43+import Foo as F
44+import Qux (Q(..), q)
45+import qualified A
46+```
Data/Aeson.hs+2−4
@@ -111,13 +111,11 @@ module Data.Aeson
111111 ) where
112112
113113import Prelude ()
114−import Prelude.Compat (Maybe, either, Either(..), uncurry, String, (.))
114+import Prelude.Compat
115115
116116import Data.Aeson.Types.FromJSON (ifromJSON)
117117import Data.Aeson.Encoding (encodingToLazyByteString)
118−import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
119− eitherDecodeWith, eitherDecodeStrictWith,
120− jsonEOF, json, jsonEOF', json')
118+import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith, eitherDecodeWith, eitherDecodeStrictWith, jsonEOF, json, jsonEOF', json')
121119import Data.Aeson.Types
122120import Data.Aeson.Types.Internal (JSONPath, formatError)
123121import qualified Data.ByteString as B
Data/Aeson/Encode.hs+4−2
@@ -9,13 +9,15 @@
99--
1010-- This module is left to supply limited backwards-compatibility.
1111module Data.Aeson.Encode {-# DEPRECATED "Use Data.Aeson or Data.Aeson.Text instead" #-}
12− ( encode
12+ (
13+ encode
1314 , encodeToTextBuilder
1415 ) where
1516
17+import Prelude ()
18+
1619import Data.ByteString.Lazy (ByteString)
1720import Data.Text.Lazy.Builder (Builder)
18−
1921import qualified Data.Aeson as A
2022import qualified Data.Aeson.Text as A
2123
Data/Aeson/Encoding.hs+3−1
@@ -8,7 +8,7 @@ module Data.Aeson.Encoding
88 -- * Encoding
99 Encoding
1010 , Encoding'
11− , encodingToLazyByteString
11+ , encodingToLazyByteString
1212 , fromEncoding
1313 , unsafeToEncoding
1414 , Series
@@ -47,4 +47,6 @@ module Data.Aeson.Encoding
4747 , value
4848 ) where
4949
50+import Prelude ()
51+
5052import Data.Aeson.Encoding.Internal
Data/Aeson/Encoding/Builder.hs+3−1
@@ -1,4 +1,6 @@
1−{-# LANGUAGE BangPatterns, CPP, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE CPP #-}
3+{-# LANGUAGE OverloadedStrings #-}
24
35-- |
46-- Module: Data.Aeson.Encoding.Builder
Data/Aeson/Encoding/Internal.hs+14−17
@@ -1,7 +1,7 @@
11{-# LANGUAGE DeriveDataTypeable #-}
2−{-# LANGUAGE EmptyDataDecls #-}
3−{-# LANGUAGE OverloadedStrings #-}
4−{-# LANGUAGE RankNTypes #-}
2+{-# LANGUAGE EmptyDataDecls #-}
3+{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE RankNTypes #-}
55module Data.Aeson.Encoding.Internal
66 (
77 -- * Encoding
@@ -53,25 +53,22 @@ module Data.Aeson.Encoding.Internal
5353 , comma, colon, openBracket, closeBracket, openCurly, closeCurly
5454 ) where
5555
56−import Prelude ()
56+import Prelude ()
5757import Prelude.Compat
5858
59−import Data.ByteString.Builder (Builder, char7, toLazyByteString)
59+import Data.Aeson.Types.Internal (Value)
60+import Data.ByteString.Builder (Builder, char7, toLazyByteString)
6061import Data.Int
61−import Data.Scientific (Scientific)
62−import Data.Semigroup (Semigroup ((<>)))
63−import Data.Text (Text)
64−import Data.Time (Day, LocalTime, TimeOfDay, UTCTime,
65− ZonedTime)
66−import Data.Typeable (Typeable)
62+import Data.Scientific (Scientific)
63+import Data.Semigroup (Semigroup ((<>)))
64+import Data.Text (Text)
65+import Data.Time (Day, LocalTime, TimeOfDay, UTCTime, ZonedTime)
66+import Data.Typeable (Typeable)
6767import Data.Word
68−
69−import Data.Aeson.Types.Internal (Value)
70−
7168import qualified Data.Aeson.Encoding.Builder as EB
72−import qualified Data.ByteString.Builder as B
73−import qualified Data.ByteString.Lazy as BSL
74−import qualified Data.Text.Lazy as LT
69+import qualified Data.ByteString.Builder as B
70+import qualified Data.ByteString.Lazy as BSL
71+import qualified Data.Text.Lazy as LT
7572
7673-- | An encoding of a JSON value.
7774--
Data/Aeson/Internal.hs+2
@@ -22,5 +22,7 @@ module Data.Aeson.Internal
2222 , iparse
2323 ) where
2424
25+import Prelude ()
26+
2527import Data.Aeson.Types.Internal
2628import Data.Aeson.Types.FromJSON (ifromJSON)
Data/Aeson/Internal/Functions.hs+2−1
@@ -8,7 +8,8 @@
88-- Portability: portable
99
1010module Data.Aeson.Internal.Functions
11− ( mapHashKeyVal
11+ (
12+ mapHashKeyVal
1213 , mapKeyVal
1314 , mapKey
1415 ) where
Data/Aeson/Parser.hs+3−3
@@ -46,9 +46,9 @@ module Data.Aeson.Parser
4646 , eitherDecodeStrictWith
4747 ) where
4848
49−import Data.Aeson.Parser.Internal (decodeStrictWith, decodeWith,
50− eitherDecodeStrictWith, eitherDecodeWith,
51− json, json', jstring, value, value')
49+import Prelude ()
50+
51+import Data.Aeson.Parser.Internal (decodeStrictWith, decodeWith, eitherDecodeStrictWith, eitherDecodeWith, json, json', jstring, value, value')
5252
5353-- $lazy
5454--
Data/Aeson/Parser/Internal.hs+4−3
@@ -1,4 +1,6 @@
1−{-# LANGUAGE BangPatterns, CPP, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE CPP #-}
3+{-# LANGUAGE OverloadedStrings #-}
24#if MIN_VERSION_ghc_prim(0,3,1)
35{-# LANGUAGE MagicHash #-}
46#endif
@@ -36,8 +38,7 @@ import Prelude.Compat
3638
3739import Control.Monad.IO.Class (liftIO)
3840import Data.Aeson.Types.Internal (IResult(..), JSONPath, Result(..), Value(..))
39−import Data.Attoparsec.ByteString.Char8 (Parser, char, endOfInput, scientific,
40− skipSpace, string)
41+import Data.Attoparsec.ByteString.Char8 (Parser, char, endOfInput, scientific, skipSpace, string)
4142import Data.Bits ((.|.), shiftL)
4243import Data.ByteString.Internal (ByteString(..))
4344import Data.Char (chr)
Data/Aeson/Parser/Time.hs+3−2
@@ -1,4 +1,5 @@
1−{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
23
34-- |
45-- Module: Data.Aeson.Parser.Time
@@ -24,7 +25,7 @@ module Data.Aeson.Parser.Time
2425import Prelude ()
2526import Prelude.Compat
2627
27−import Control.Monad (when, void)
28+import Control.Monad (void, when)
2829import Data.Aeson.Internal.Time (toPico)
2930import Data.Attoparsec.Text as A
3031import Data.Bits ((.&.))
Data/Aeson/TH.hs+38−58
@@ -86,8 +86,12 @@ $('deriveJSON' 'defaultOptions' ''(,,,))
8686-}
8787
8888module Data.Aeson.TH
89− ( -- * Encoding configuration
90− Options(..), SumEncoding(..), defaultOptions, defaultTaggedObject
89+ (
90+ -- * Encoding configuration
91+ Options(..)
92+ , SumEncoding(..)
93+ , defaultOptions
94+ , defaultTaggedObject
9195
9296 -- * FromJSON and ToJSON derivation
9397 , deriveJSON
@@ -112,71 +116,47 @@ module Data.Aeson.TH
112116 , mkLiftParseJSON2
113117 ) where
114118
115−import Control.Applicative ( pure, (<$>), (<*>), (<|>) )
116−import Data.Aeson ( Object, (.=), (.:)
117− , ToJSON(..), FromJSON(..)
118− , ToJSON1(..), FromJSON1(..)
119− , ToJSON2(..), FromJSON2(..)
120− )
121−import Data.Aeson.Types ( Value(..), Parser
122− , Options(..)
123− , SumEncoding(..)
124− , defaultOptions
125− , defaultTaggedObject
126− )
127−import Data.Aeson.Types.Internal (Pair, (<?>), JSONPathElement(Key))
119+import Prelude ()
120+import Prelude.Compat hiding (exp)
121+
122+import Control.Applicative ((<|>))
123+import Data.Aeson (Object, (.=), (.:), FromJSON(..), FromJSON1(..), FromJSON2(..), ToJSON(..), ToJSON1(..), ToJSON2(..))
124+import Data.Aeson.Types (Options(..), Parser, SumEncoding(..), Value(..), defaultOptions, defaultTaggedObject)
125+import Data.Aeson.Types.Internal ((<?>), Pair, JSONPathElement(Key))
128126import Data.Aeson.Types.FromJSON (parseOptionalFieldWith)
129−import Control.Monad ( fail, liftM2, mapM, return, unless, when )
130−import Data.Bool ( Bool(False, True), otherwise, (&&), not )
131−import Data.Either ( Either(Left, Right) )
132−import Data.Eq ( (==) )
133−import Data.Foldable ( concatMap, foldr' )
134−import Data.Function ( ($), (.), flip )
135−import Data.Functor ( fmap )
136−import Data.Int ( Int )
137−import Data.List ( (++), all, any, find, foldl, foldl'
138− , genericLength , intercalate , intersperse, length, map
139− , partition, union, zip, zip3
140− )
141−import Data.List.NonEmpty ( NonEmpty((:|)), (<|) )
142−import Data.Map ( Map )
143−import Data.Maybe ( Maybe(Nothing, Just), catMaybes, fromMaybe, mapMaybe )
144−import Data.Set ( Set )
145−import Language.Haskell.TH
127+import Control.Monad (liftM2, unless, when)
128+import Data.Foldable (foldr')
129+#if MIN_VERSION_template_haskell(2,8,0) && !MIN_VERSION_template_haskell(2,10,0)
130+import Data.List (nub)
131+#endif
132+import Data.List (find, foldl', genericLength , intercalate , intersperse, partition, union)
133+import Data.List.NonEmpty ((<|), NonEmpty((:|)))
134+import Data.Map (Map)
135+import Data.Maybe (catMaybes, fromMaybe, mapMaybe)
136+import Data.Set (Set)
146137#if MIN_VERSION_template_haskell(2,8,0)
147− hiding ( Arity )
138+import Language.Haskell.TH hiding (Arity)
139+#else
140+import Language.Haskell.TH
148141#endif
149−import Language.Haskell.TH.Syntax ( VarStrictType )
150−import Prelude ( Enum(..), Eq(..), Integer, Ord(..), String
151− , concat, cycle, drop, elem, error, foldr1, fromIntegral
152− , showChar, showParen, shows, showString, snd, splitAt
153− , take, unzip, zipWith, (-), (||)
154− )
142+import Language.Haskell.TH.Syntax (VarStrictType)
155143#if MIN_VERSION_template_haskell(2,7,0) && !(MIN_VERSION_template_haskell(2,8,0))
156−import Language.Haskell.TH.Lib ( starK )
144+import Language.Haskell.TH.Lib (starK)
157145#endif
158146#if MIN_VERSION_template_haskell(2,8,0) && !(MIN_VERSION_template_haskell(2,10,0))
159−import Data.List ( nub )
160−import Language.Haskell.TH.Syntax ( mkNameG_tc )
161−import Prelude ( uncurry )
162−#endif
163−#if MIN_VERSION_template_haskell(2,11,0)
164−import Prelude ( head )
147+import Language.Haskell.TH.Syntax (mkNameG_tc)
165148#endif
166−import Text.Printf ( printf )
167−import Text.Show ( show )
149+import Text.Printf (printf)
168150import qualified Data.Aeson as A
169151import qualified Data.Aeson.Encoding.Internal as E
170−import qualified Data.Foldable as F ( all )
171−import qualified Data.HashMap.Strict as H ( lookup, toList )
172−import qualified Data.List.NonEmpty as NE ( drop, length, reverse, splitAt )
173−import qualified Data.Map as M ( fromList, findWithDefault, keys, lookup
174− , singleton, size
175− )
176−import qualified Data.Set as Set ( empty, insert, member )
177−import qualified Data.Text as T ( Text, pack, unpack )
178−import qualified Data.Vector as V ( unsafeIndex, null, length, create, fromList )
179−import qualified Data.Vector.Mutable as VM ( unsafeNew, unsafeWrite )
152+import qualified Data.Foldable as F (all)
153+import qualified Data.HashMap.Strict as H (lookup, toList)
154+import qualified Data.List.NonEmpty as NE (drop, length, reverse, splitAt)
155+import qualified Data.Map as M (fromList, findWithDefault, keys, lookup , singleton, size)
156+import qualified Data.Set as Set (empty, insert, member)
157+import qualified Data.Text as T (Text, pack, unpack)
158+import qualified Data.Vector as V (unsafeIndex, null, length, create, fromList)
159+import qualified Data.Vector.Mutable as VM (unsafeNew, unsafeWrite)
180160
181161
182162--------------------------------------------------------------------------------
Data/Aeson/Text.hs+8−4
@@ -1,4 +1,5 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE OverloadedStrings #-}
23-- |
34-- Module: Data.Aeson.Text
45-- Copyright: (c) 2012-2016 Bryan O'Sullivan
@@ -14,17 +15,20 @@
1415-- You can use the conversions to 'Builder's when embedding JSON messages as
1516-- parts of a protocol.
1617module Data.Aeson.Text
17− ( encodeToLazyText
18+ (
19+ encodeToLazyText
1820 , encodeToTextBuilder
1921 ) where
2022
23+import Prelude ()
24+import Prelude.Compat
25+
2126import Data.Aeson.Types (Value(..), ToJSON(..))
2227import Data.Aeson.Encoding (encodingToLazyByteString)
2328import Data.Monoid ((<>))
2429import Data.Scientific (FPFormat(..), Scientific, base10Exponent)
2530import Data.Text.Lazy.Builder
2631import Data.Text.Lazy.Builder.Scientific (formatScientificBuilder)
27−
2832import Numeric (showHex)
2933import qualified Data.HashMap.Strict as H
3034import qualified Data.Text as T
@@ -36,7 +40,7 @@ import qualified Data.Vector as V
3640--
3741-- /Note:/ uses 'toEncoding'
3842encodeToLazyText :: ToJSON a => a -> LT.Text
39−encodeToLazyText = LT.decodeUtf8 . encodingToLazyByteString . toEncoding
43+encodeToLazyText = LT.decodeUtf8 . encodingToLazyByteString . toEncoding
4044
4145-- | Encode a JSON 'Value' to a "Data.Text" 'Builder', which can be
4246-- embedded efficiently in a text-based protocol.
Data/Aeson/Types.hs+1−2
@@ -107,10 +107,9 @@ module Data.Aeson.Types
107107import Prelude ()
108108import Prelude.Compat
109109
110+import Data.Aeson.Encoding (Encoding, unsafeToEncoding, fromEncoding, Series, pairs)
110111import Data.Aeson.Types.Class
111112import Data.Aeson.Types.Internal
112−import Data.Aeson.Encoding (Encoding, unsafeToEncoding, fromEncoding, Series, pairs)
113−
114113import Data.Foldable (toList)
115114
116115-- | Encode a 'Foldable' as a JSON array.
Data/Aeson/Types/Class.hs+3−1
@@ -83,6 +83,8 @@ module Data.Aeson.Types.Class
8383 , typeMismatch
8484 ) where
8585
86+import Prelude ()
87+
8688import Data.Aeson.Types.FromJSON
87−import Data.Aeson.Types.ToJSON
8889import Data.Aeson.Types.Generic (One, Zero)
90+import Data.Aeson.Types.ToJSON
Data/Aeson/Types/FromJSON.hs+68−73
@@ -1,21 +1,21 @@
1−{-# LANGUAGE CPP #-}
2−{-# LANGUAGE DataKinds #-}
3−{-# LANGUAGE DefaultSignatures #-}
4−{-# LANGUAGE FlexibleContexts #-}
5−{-# LANGUAGE FlexibleInstances #-}
6−{-# LANGUAGE GADTs #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE DefaultSignatures #-}
4+{-# LANGUAGE FlexibleContexts #-}
5+{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE GADTs #-}
77{-# LANGUAGE MultiParamTypeClasses #-}
8−{-# LANGUAGE NamedFieldPuns #-}
9−{-# LANGUAGE OverloadedStrings #-}
10−{-# LANGUAGE RecordWildCards #-}
11−{-# LANGUAGE ScopedTypeVariables #-}
12−{-# LANGUAGE TypeOperators #-}
13−{-# LANGUAGE TypeSynonymInstances #-}
14−{-# LANGUAGE UndecidableInstances #-}
15−{-# LANGUAGE ViewPatterns #-}
8+{-# LANGUAGE NamedFieldPuns #-}
9+{-# LANGUAGE OverloadedStrings #-}
10+{-# LANGUAGE RecordWildCards #-}
11+{-# LANGUAGE ScopedTypeVariables #-}
12+{-# LANGUAGE TypeOperators #-}
13+{-# LANGUAGE TypeSynonymInstances #-}
14+{-# LANGUAGE UndecidableInstances #-}
15+{-# LANGUAGE ViewPatterns #-}
1616
1717#if __GLASGOW_HASKELL__ >= 706
18−{-# LANGUAGE PolyKinds #-}
18+{-# LANGUAGE PolyKinds #-}
1919#endif
2020
2121#include "overlapping-compat.h"
@@ -23,7 +23,8 @@
2323-- TODO: Drop this when we remove support for Data.Attoparsec.Number
2424{-# OPTIONS_GHC -fno-warn-deprecations #-}
2525
26−module Data.Aeson.Types.FromJSON (
26+module Data.Aeson.Types.FromJSON
27+ (
2728 -- * Core JSON classes
2829 FromJSON(..)
2930 -- * Liftings to unary and binary type constructors
@@ -46,7 +47,7 @@ module Data.Aeson.Types.FromJSON (
4647 -- * List functions
4748 , listParser
4849
49− -- * Inspecting @'Value's@
50+ -- * Inspecting @'Value's@
5051 , withObject
5152 , withText
5253 , withArray
@@ -67,68 +68,62 @@ module Data.Aeson.Types.FromJSON (
6768 , parseOptionalFieldWith
6869 ) where
6970
70−import Prelude ()
71−import Prelude.Compat hiding (foldr)
71+import Prelude ()
72+import Prelude.Compat
7273
74+import Control.Applicative ((<|>), Const(..))
75+import Control.Monad ((<=<), zipWithM)
7376import Data.Aeson.Internal.Functions (mapKey)
7477import Data.Aeson.Types.Generic
7578import Data.Aeson.Types.Internal
76−
77−import qualified Data.Aeson.Parser.Time as Time
78−import qualified Data.Attoparsec.ByteString.Char8 as A (endOfInput, parseOnly,
79− scientific)
80−
81−import Control.Applicative (Const (..), (<|>))
82−import Control.Monad ((<=<), zipWithM)
83−import Data.Attoparsec.Number (Number (..))
84−import Data.Bits (unsafeShiftR)
85−import Data.Fixed (Fixed, HasResolution)
86−import Data.Functor.Compose (Compose (..))
87−import Data.Functor.Identity (Identity (..))
88−import Data.Functor.Product (Product (..))
89−import Data.Functor.Sum (Sum (..))
90−import Data.Hashable (Hashable (..))
91−import Data.Int (Int16, Int32, Int64, Int8)
92−import Data.List.NonEmpty (NonEmpty (..))
93−import Data.Maybe (fromMaybe)
94−import Data.Monoid (Dual (..), First (..), Last (..), (<>))
95−import Data.Proxy (Proxy (..))
96−import Data.Ratio (Ratio, (%))
97−import Data.Scientific (Scientific)
98−import Data.Tagged (Tagged (..))
99−import Data.Text (Text, pack, unpack)
100−import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay,
101− UTCTime, ZonedTime)
102−import Data.Time.Format (parseTime)
103−import Data.Time.Locale.Compat (defaultTimeLocale)
104−import Data.Traversable as Tr (sequence)
105−import Data.Vector (Vector)
106−import Data.Version (Version, parseVersion)
107−import Data.Word (Word16, Word32, Word64, Word8)
108−import Foreign.Storable (Storable)
79+import Data.Attoparsec.Number (Number(..))
80+import Data.Bits (unsafeShiftR)
81+import Data.Fixed (Fixed, HasResolution)
82+import Data.Functor.Compose (Compose(..))
83+import Data.Functor.Identity (Identity(..))
84+import Data.Functor.Product (Product(..))
85+import Data.Functor.Sum (Sum(..))
86+import Data.Hashable (Hashable(..))
87+import Data.Int (Int16, Int32, Int64, Int8)
88+import Data.List.NonEmpty (NonEmpty(..))
89+import Data.Maybe (fromMaybe)
90+import Data.Monoid ((<>), Dual(..), First (..), Last (..))
91+import Data.Proxy (Proxy(..))
92+import Data.Ratio ((%), Ratio)
93+import Data.Scientific (Scientific)
94+import Data.Tagged (Tagged(..))
95+import Data.Text (Text, pack, unpack)
96+import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime, ZonedTime)
97+import Data.Time.Format (parseTime)
98+import Data.Time.Locale.Compat (defaultTimeLocale)
99+import Data.Traversable as Tr (sequence)
100+import Data.Vector (Vector)
101+import Data.Version (Version, parseVersion)
102+import Data.Word (Word16, Word32, Word64, Word8)
103+import Foreign.Storable (Storable)
109104import GHC.Generics
110−import Numeric.Natural (Natural)
105+import Numeric.Natural (Natural)
111106import Text.ParserCombinators.ReadP (readP_to_S)
112−
113−import qualified Data.DList as DList
114−import qualified Data.HashMap.Strict as H
115−import qualified Data.HashSet as HashSet
116−import qualified Data.IntMap as IntMap
117−import qualified Data.IntSet as IntSet
118−import qualified Data.Map as M
119−import qualified Data.Scientific as Scientific
120−import qualified Data.Sequence as Seq
121−import qualified Data.Set as Set
122−import qualified Data.Text as T
123−import qualified Data.Text.Encoding as T
124−import qualified Data.Text.Lazy as LT
125−import qualified Data.Tree as Tree
126−import qualified Data.Vector as V
127−import qualified Data.Vector.Generic as VG
107+import qualified Data.Aeson.Parser.Time as Time
108+import qualified Data.Attoparsec.ByteString.Char8 as A (endOfInput, parseOnly, scientific)
109+import qualified Data.DList as DList
110+import qualified Data.HashMap.Strict as H
111+import qualified Data.HashSet as HashSet
112+import qualified Data.IntMap as IntMap
113+import qualified Data.IntSet as IntSet
114+import qualified Data.Map as M
115+import qualified Data.Scientific as Scientific
116+import qualified Data.Sequence as Seq
117+import qualified Data.Set as Set
118+import qualified Data.Text as T
119+import qualified Data.Text.Encoding as T
120+import qualified Data.Text.Lazy as LT
121+import qualified Data.Tree as Tree
122+import qualified Data.Vector as V
123+import qualified Data.Vector.Generic as VG
128124import qualified Data.Vector.Primitive as VP
129−import qualified Data.Vector.Storable as VS
130−import qualified Data.Vector.Unboxed as VU
131−
125+import qualified Data.Vector.Storable as VS
126+import qualified Data.Vector.Unboxed as VU
132127import Unsafe.Coerce (unsafeCoerce)
133128
134129#ifndef HAS_COERCIBLE
@@ -1184,7 +1179,7 @@ instance FromJSON Int where
11841179 {-# INLINE parseJSON #-}
11851180
11861181instance FromJSONKey Int where
1187− fromJSONKey = FromJSONKeyTextParser $ parseBoundedIntegralText "Int"
1182+ fromJSONKey = FromJSONKeyTextParser $ parseBoundedIntegralText "Int"
11881183
11891184-- | /WARNING:/ Only parse Integers from trusted input since an
11901185-- attacker could easily fill up the memory of the target system by
Data/Aeson/Types/Generic.hs+21−10
@@ -1,13 +1,13 @@
1−{-# LANGUAGE CPP #-}
2−{-# LANGUAGE DataKinds #-}
3−{-# LANGUAGE EmptyDataDecls #-}
4−{-# LANGUAGE FlexibleInstances #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE EmptyDataDecls #-}
4+{-# LANGUAGE FlexibleInstances #-}
55{-# LANGUAGE FunctionalDependencies #-}
6−{-# LANGUAGE KindSignatures #-}
7−{-# LANGUAGE MultiParamTypeClasses #-}
8−{-# LANGUAGE ScopedTypeVariables #-}
9−{-# LANGUAGE TypeOperators #-}
10−{-# LANGUAGE UndecidableInstances #-}
6+{-# LANGUAGE KindSignatures #-}
7+{-# LANGUAGE MultiParamTypeClasses #-}
8+{-# LANGUAGE ScopedTypeVariables #-}
9+{-# LANGUAGE TypeOperators #-}
10+{-# LANGUAGE UndecidableInstances #-}
1111
1212#include "overlapping-compat.h"
1313
@@ -23,7 +23,18 @@
2323--
2424-- Helpers for generic derivations.
2525
26−module Data.Aeson.Types.Generic where
26+module Data.Aeson.Types.Generic
27+ (
28+ IsRecord(..)
29+ , AllNullary
30+ , Tagged2(..)
31+ , True
32+ , False
33+ , And
34+ , Zero
35+ , One
36+ , ProductSize(..)
37+ ) where
2738
2839import Prelude ()
2940import Prelude.Compat
Data/Aeson/Types/Internal.hs+8−5
@@ -1,5 +1,8 @@
1−{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving, Rank2Types,
2− RecordWildCards #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4+{-# LANGUAGE Rank2Types #-}
5+{-# LANGUAGE RecordWildCards #-}
36#if __GLASGOW_HASKELL__ >= 800
47-- a) THQ works on cross-compilers and unregisterised GHCs
58-- b) may make compilation faster as no dynamic loading is ever needed (not sure about this)
@@ -63,24 +66,24 @@ module Data.Aeson.Types.Internal
6366import Prelude ()
6467import Prelude.Compat
6568
66−import Control.Arrow (first)
6769import Control.Applicative (Alternative(..))
70+import Control.Arrow (first)
6871import Control.DeepSeq (NFData(..))
6972import Control.Monad (MonadPlus(..), ap)
70−import qualified Control.Monad.Fail as Fail
7173import Data.Char (isLower, isUpper, toLower, isAlpha, isAlphaNum)
7274import Data.Data (Data)
7375import Data.Foldable (foldl')
7476import Data.HashMap.Strict (HashMap)
7577import Data.Hashable (Hashable(..))
76−import Data.Semigroup (Semigroup((<>)))
7778import Data.Scientific (Scientific)
79+import Data.Semigroup (Semigroup((<>)))
7880import Data.String (IsString(..))
7981import Data.Text (Text, pack, unpack)
8082import Data.Time (UTCTime)
8183import Data.Time.Format (FormatTime)
8284import Data.Typeable (Typeable)
8385import Data.Vector (Vector)
86+import qualified Control.Monad.Fail as Fail
8487import qualified Data.HashMap.Strict as H
8588import qualified Data.Scientific as S
8689import qualified Data.Vector as V
Data/Aeson/Types/ToJSON.hs+242−239
@@ -1,22 +1,22 @@
1−{-# LANGUAGE BangPatterns #-}
2−{-# LANGUAGE CPP #-}
3−{-# LANGUAGE DataKinds #-}
4−{-# LANGUAGE DefaultSignatures #-}
5−{-# LANGUAGE FlexibleContexts #-}
6−{-# LANGUAGE FlexibleInstances #-}
7−{-# LANGUAGE GADTs #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE CPP #-}
3+{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE DefaultSignatures #-}
5+{-# LANGUAGE FlexibleContexts #-}
6+{-# LANGUAGE FlexibleInstances #-}
7+{-# LANGUAGE GADTs #-}
88{-# LANGUAGE MultiParamTypeClasses #-}
9−{-# LANGUAGE NamedFieldPuns #-}
10−{-# LANGUAGE OverloadedStrings #-}
11−{-# LANGUAGE PatternGuards #-}
12−{-# LANGUAGE RecordWildCards #-}
13−{-# LANGUAGE ScopedTypeVariables #-}
14−{-# LANGUAGE TypeOperators #-}
15−{-# LANGUAGE TypeSynonymInstances #-}
16−{-# LANGUAGE UndecidableInstances #-}
9+{-# LANGUAGE NamedFieldPuns #-}
10+{-# LANGUAGE OverloadedStrings #-}
11+{-# LANGUAGE PatternGuards #-}
12+{-# LANGUAGE RecordWildCards #-}
13+{-# LANGUAGE ScopedTypeVariables #-}
14+{-# LANGUAGE TypeOperators #-}
15+{-# LANGUAGE TypeSynonymInstances #-}
16+{-# LANGUAGE UndecidableInstances #-}
1717
1818#if __GLASGOW_HASKELL__ >= 706
19−{-# LANGUAGE PolyKinds #-}
19+{-# LANGUAGE PolyKinds #-}
2020#endif
2121
2222#include "overlapping-compat.h"
@@ -24,7 +24,8 @@
2424-- TODO: Drop this when we remove support for Data.Attoparsec.Number
2525{-# OPTIONS_GHC -fno-warn-deprecations #-}
2626
27−module Data.Aeson.Types.ToJSON (
27+module Data.Aeson.Types.ToJSON
28+ (
2829 -- * Core JSON classes
2930 ToJSON(..)
3031 -- * Liftings to unary and binary type constructors
@@ -55,78 +56,73 @@ module Data.Aeson.Types.ToJSON (
5556 , listValue
5657 ) where
5758
58−import Prelude ()
59+import Prelude ()
5960import Prelude.Compat
6061
61−import Data.Aeson.Encoding.Internal (Encoding, Encoding', Series, dict,
62− emptyArray_, tuple, (>*<), (><))
62+import Control.Applicative (Const(..))
63+import Control.Monad.ST (ST)
64+import Data.Aeson.Encoding (Encoding, Encoding', Series, dict, emptyArray_)
65+import Data.Aeson.Encoding.Internal ((>*<), (><))
6366import Data.Aeson.Internal.Functions (mapHashKeyVal, mapKeyVal)
64−import Data.Aeson.Types.Generic
67+import Data.Aeson.Types.Generic (AllNullary, False, IsRecord(..), One, ProductSize, Tagged2(..), True, Zero, productSize)
6568import Data.Aeson.Types.Internal
66−
67−-- We need internal here for generic deriving
68−import qualified Data.Aeson.Encoding.Internal as E
69−
70−import Control.Applicative (Const (..))
71−import Control.Monad.ST (ST)
72−import Data.Attoparsec.Number (Number (..))
73−import Data.Bits (unsafeShiftR)
74−import Data.DList (DList)
75−import Data.Fixed (Fixed, HasResolution)
76−import Data.Foldable (toList)
77−import Data.Functor.Compose (Compose (..))
78−import Data.Functor.Identity (Identity (..))
79−import Data.Functor.Product (Product (..))
80−import Data.Functor.Sum (Sum (..))
81−import Data.Int (Int16, Int32, Int64, Int8)
82−import Data.List (intersperse)
83−import Data.List.NonEmpty (NonEmpty (..))
84−import Data.Monoid (Dual (..), First (..), Last (..), (<>))
85−import Data.Proxy (Proxy (..))
86−import Data.Ratio (Ratio, denominator, numerator)
87−import Data.Scientific (Scientific)
88−import Data.Tagged (Tagged (..))
89−import Data.Text (Text, pack)
90−import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay,
91− UTCTime, ZonedTime)
92−import Data.Time.Format (FormatTime, formatTime)
69+import Data.Attoparsec.Number (Number(..))
70+import Data.Bits (unsafeShiftR)
71+import Data.DList (DList)
72+import Data.Fixed (Fixed, HasResolution)
73+import Data.Foldable (toList)
74+import Data.Functor.Compose (Compose(..))
75+import Data.Functor.Identity (Identity(..))
76+import Data.Functor.Product (Product(..))
77+import Data.Functor.Sum (Sum(..))
78+import Data.Int (Int16, Int32, Int64, Int8)
79+import Data.List (intersperse)
80+import Data.List.NonEmpty (NonEmpty(..))
81+import Data.Monoid ((<>), Dual(..), First(..), Last(..))
82+import Data.Proxy (Proxy(..))
83+import Data.Ratio (Ratio, denominator, numerator)
84+import Data.Scientific (Scientific)
85+import Data.Tagged (Tagged(..))
86+import Data.Text (Text, pack)
87+import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime, ZonedTime)
88+import Data.Time.Format (FormatTime, formatTime)
9389import Data.Time.Locale.Compat (defaultTimeLocale)
94−import Data.Vector (Vector)
95−import Data.Version (Version, showVersion)
96−import Data.Word (Word16, Word32, Word64, Word8)
97−import Foreign.Storable (Storable)
90+import Data.Vector (Vector)
91+import Data.Version (Version, showVersion)
92+import Data.Word (Word16, Word32, Word64, Word8)
93+import Foreign.Storable (Storable)
9894import GHC.Generics
99−import Numeric.Natural (Natural)
100−
101−import qualified Data.ByteString as S
102−import qualified Data.ByteString.Lazy as L
103−import qualified Data.DList as DList
104−import qualified Data.HashMap.Strict as H
105−import qualified Data.HashSet as HashSet
106−import qualified Data.IntMap as IntMap
107−import qualified Data.IntSet as IntSet
108−import qualified Data.List.NonEmpty as NE
109−import qualified Data.Map as M
110−import qualified Data.Scientific as Scientific
111−import qualified Data.Sequence as Seq
112−import qualified Data.Set as Set
113−import qualified Data.Text as T
114−import qualified Data.Text.Encoding as T
115−import qualified Data.Text.Lazy as LT
116−import qualified Data.Tree as Tree
117−import qualified Data.Vector as V
118−import qualified Data.Vector.Generic as VG
119−import qualified Data.Vector.Mutable as VM
95+import Numeric.Natural (Natural)
96+import qualified Data.Aeson.Encoding as E
97+import qualified Data.Aeson.Encoding.Internal as E (InArray, colon, comma, econcat, empty, retagEncoding, wrapObject)
98+import qualified Data.ByteString as S
99+import qualified Data.ByteString.Lazy as L
100+import qualified Data.DList as DList
101+import qualified Data.HashMap.Strict as H
102+import qualified Data.HashSet as HashSet
103+import qualified Data.IntMap as IntMap
104+import qualified Data.IntSet as IntSet
105+import qualified Data.List.NonEmpty as NE
106+import qualified Data.Map as M
107+import qualified Data.Scientific as Scientific
108+import qualified Data.Sequence as Seq
109+import qualified Data.Set as Set
110+import qualified Data.Text as T
111+import qualified Data.Text.Encoding as T
112+import qualified Data.Text.Lazy as LT
113+import qualified Data.Tree as Tree
114+import qualified Data.Vector as V
115+import qualified Data.Vector.Generic as VG
116+import qualified Data.Vector.Mutable as VM
120117import qualified Data.Vector.Primitive as VP
121−import qualified Data.Vector.Storable as VS
122−import qualified Data.Vector.Unboxed as VU
118+import qualified Data.Vector.Storable as VS
119+import qualified Data.Vector.Unboxed as VU
123120
124121#if !(MIN_VERSION_bytestring(0,10,0))
125−import Foreign.ForeignPtr (withForeignPtr)
122+import Foreign.ForeignPtr (withForeignPtr)
126123import Foreign.Marshal.Utils (copyBytes)
127−import Foreign.Ptr (plusPtr)
128−
129−import qualified Data.ByteString.Internal as S
124+import Foreign.Ptr (plusPtr)
125+import qualified Data.ByteString.Internal as S
130126import qualified Data.ByteString.Lazy.Internal as L
131127#endif
132128
@@ -725,7 +721,7 @@ instance ( EncodeProduct arity a
725721 -- Products are encoded to an array. Here we allocate a mutable vector of
726722 -- the same size as the product and write the product's elements to it using
727723 -- 'encodeProduct':
728− gToEncoding opts targs p = E.tuple $ encodeProduct opts targs p
724+ gToEncoding opts targs p = E.list E.retagEncoding [encodeProduct opts targs p]
729725
730726instance ( AllNullary (a :+: b) allNullary
731727 , SumToEncoding arity (a :+: b) allNullary
@@ -880,13 +876,12 @@ instance ( IsRecord a isRecord
880876 , TaggedObjectEnc' arity a isRecord
881877 , Constructor c
882878 ) => TaggedObjectEnc arity (C1 c a) where
883− taggedObjectEnc opts targs tagFieldName contentsFieldName v =
884− E.wrapObject $
885− (E.string tagFieldName ><
886− E.colon ><
887− toEncoding (constructorTagModifier opts (conName (undefined :: t c a p)))) ><
888− ((unTagged :: Tagged isRecord Encoding -> Encoding) .
889− taggedObjectEnc' opts targs contentsFieldName . unM1 $ v)
879+ taggedObjectEnc opts targs tagFieldName contentsFieldName v = E.pairs (E.pair key val)
880+ where
881+ key :: Text
882+ key = pack tagFieldName
883+ val = toEncoding (constructorTagModifier opts (conName (undefined :: t c a p)))
884+ >< ((unTagged :: Tagged isRecord Encoding -> Encoding) . taggedObjectEnc' opts targs contentsFieldName . unM1 $ v)
890885
891886class TaggedObjectEnc' arity f isRecord where
892887 taggedObjectEnc' :: Options -> ToArgs Encoding arity a
@@ -956,9 +951,10 @@ instance ( GToEncoding arity a
956951 , ConsToEncoding arity a
957952 , Constructor c
958953 ) => TwoElemArrayEnc arity (C1 c a) where
959− twoElemArrayEnc opts targs x = E.tuple $
960− toEncoding (constructorTagModifier opts (conName (undefined :: t c a p))) >*<
961− gToEncoding opts targs x
954+ twoElemArrayEnc opts targs x = E.list id
955+ [ toEncoding (constructorTagModifier opts (conName (undefined :: t c a p)))
956+ , gToEncoding opts targs x
957+ ]
962958
963959--------------------------------------------------------------------------------
964960
@@ -1124,8 +1120,9 @@ instance ( EncodeProduct arity a
11241120 E.econcat $ intersperse E.comma $
11251121 filter (not . E.nullEncoding)
11261122 [encodeProduct opts targs a, encodeProduct opts targs b]
1127− encodeProduct opts targs (a :*: b) = encodeProduct opts targs a >*<
1128− encodeProduct opts targs b
1123+ encodeProduct opts targs (a :*: b) =
1124+ encodeProduct opts targs a >*<
1125+ encodeProduct opts targs b
11291126
11301127instance OVERLAPPABLE_ (GToEncoding arity a) => EncodeProduct arity a where
11311128 encodeProduct opts targs a = E.retagEncoding $ gToEncoding opts targs a
@@ -1171,14 +1168,12 @@ instance ( GToEncoding arity a
11711168 , ConsToEncoding arity a
11721169 , Constructor c
11731170 ) => ObjectWithSingleFieldEnc arity (C1 c a) where
1174− objectWithSingleFieldEnc opts targs v =
1175− E.openCurly ><
1176− toEncoding
1177− (constructorTagModifier opts
1178− (conName (undefined :: t c a p))) ><
1179− E.colon ><
1180− gToEncoding opts targs v ><
1181− E.closeCurly
1171+ objectWithSingleFieldEnc opts targs v = E.pairs (E.pair key val)
1172+ where
1173+ key :: Text
1174+ key = pack (constructorTagModifier opts (conName (undefined :: t c a p)))
1175+ val :: Encoding' Value
1176+ val = gToEncoding opts targs v
11821177
11831178--------------------------------------------------------------------------------
11841179
@@ -1813,13 +1808,11 @@ instance ToJSONKey k => ToJSON1 (M.Map k) where
18131808 ToJSONKeyValue f _ -> Array . V.fromList . map (toJSONPair f g) . M.toList
18141809 {-# INLINE liftToJSON #-}
18151810
1816− -- liftToEncoding :: forall a. (a -> Encoding) -> ([a] -> Encoding) -> M.Map k a -> Encoding
18171811 liftToEncoding g _ = case toJSONKey of
18181812 ToJSONKeyText _ f -> dict f g M.foldrWithKey
18191813 ToJSONKeyValue _ f -> listEncoding (pairEncoding f) . M.toList
18201814 where
1821− -- pairEncoding :: (k -> Encoding) -> (k, a) -> Encoding
1822− pairEncoding f (a, b) = tuple $ f a >*< g b
1815+ pairEncoding f (a, b) = E.list id [f a, g b]
18231816 {-# INLINE liftToEncoding #-}
18241817
18251818
@@ -1937,8 +1930,7 @@ instance ToJSONKey k => ToJSON1 (H.HashMap k) where
19371930 ToJSONKeyText _ f -> dict f g H.foldrWithKey
19381931 ToJSONKeyValue _ f -> listEncoding (pairEncoding f) . H.toList
19391932 where
1940− -- pairEncoding :: (k -> Encoding) -> (k, a) -> Encoding
1941− pairEncoding f (a, b) = tuple $ f a >*< g b
1933+ pairEncoding f (a, b) = E.list id [f a, g b]
19421934 {-# INLINE liftToEncoding #-}
19431935
19441936instance (ToJSON v, ToJSONKey k) => ToJSON (H.HashMap k v) where
@@ -2125,7 +2117,7 @@ instance (ToJSONKey a, ToJSON a) => ToJSONKey [a] where
21252117 toJSONKey = toJSONKeyList
21262118
21272119-------------------------------------------------------------------------------
2128−-- Tuple instances, see tuple-instances-to.hs
2120+-- Tuple instances
21292121-------------------------------------------------------------------------------
21302122
21312123instance ToJSON2 (,) where
@@ -2136,9 +2128,7 @@ instance ToJSON2 (,) where
21362128 return mv
21372129 {-# INLINE liftToJSON2 #-}
21382130
2139− liftToEncoding2 toA _ toB _ (a, b) = tuple $
2140− toA a >*<
2141− toB b
2131+ liftToEncoding2 toA _ toB _ (a, b) = E.list id [toA a, toB b]
21422132 {-# INLINE liftToEncoding2 #-}
21432133
21442134instance (ToJSON a) => ToJSON1 ((,) a) where
@@ -2162,10 +2152,11 @@ instance (ToJSON a) => ToJSON2 ((,,) a) where
21622152 return mv
21632153 {-# INLINE liftToJSON2 #-}
21642154
2165− liftToEncoding2 toB _ toC _ (a, b, c) = tuple $
2166− toEncoding a >*<
2167− toB b >*<
2168− toC c
2155+ liftToEncoding2 toB _ toC _ (a, b, c) = E.list id
2156+ [ toEncoding a
2157+ , toB b
2158+ , toC c
2159+ ]
21692160 {-# INLINE liftToEncoding2 #-}
21702161
21712162instance (ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) where
@@ -2190,11 +2181,12 @@ instance (ToJSON a, ToJSON b) => ToJSON2 ((,,,) a b) where
21902181 return mv
21912182 {-# INLINE liftToJSON2 #-}
21922183
2193− liftToEncoding2 toC _ toD _ (a, b, c, d) = tuple $
2194− toEncoding a >*<
2195− toEncoding b >*<
2196− toC c >*<
2197− toD d
2184+ liftToEncoding2 toC _ toD _ (a, b, c, d) = E.list id
2185+ [ toEncoding a
2186+ , toEncoding b
2187+ , toC c
2188+ , toD d
2189+ ]
21982190 {-# INLINE liftToEncoding2 #-}
21992191
22002192instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) where
@@ -2220,12 +2212,13 @@ instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON2 ((,,,,) a b c) where
22202212 return mv
22212213 {-# INLINE liftToJSON2 #-}
22222214
2223− liftToEncoding2 toD _ toE _ (a, b, c, d, e) = tuple $
2224− toEncoding a >*<
2225− toEncoding b >*<
2226− toEncoding c >*<
2227− toD d >*<
2228− toE e
2215+ liftToEncoding2 toD _ toE _ (a, b, c, d, e) = E.list id
2216+ [ toEncoding a
2217+ , toEncoding b
2218+ , toEncoding c
2219+ , toD d
2220+ , toE e
2221+ ]
22292222 {-# INLINE liftToEncoding2 #-}
22302223
22312224instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) where
@@ -2252,13 +2245,14 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON2 ((,,,,,) a b c d) w
22522245 return mv
22532246 {-# INLINE liftToJSON2 #-}
22542247
2255− liftToEncoding2 toE _ toF _ (a, b, c, d, e, f) = tuple $
2256− toEncoding a >*<
2257− toEncoding b >*<
2258− toEncoding c >*<
2259− toEncoding d >*<
2260− toE e >*<
2261− toF f
2248+ liftToEncoding2 toE _ toF _ (a, b, c, d, e, f) = E.list id
2249+ [ toEncoding a
2250+ , toEncoding b
2251+ , toEncoding c
2252+ , toEncoding d
2253+ , toE e
2254+ , toF f
2255+ ]
22622256 {-# INLINE liftToEncoding2 #-}
22632257
22642258instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) where
@@ -2286,14 +2280,15 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON2 ((,,,,,,)
22862280 return mv
22872281 {-# INLINE liftToJSON2 #-}
22882282
2289− liftToEncoding2 toF _ toG _ (a, b, c, d, e, f, g) = tuple $
2290− toEncoding a >*<
2291− toEncoding b >*<
2292− toEncoding c >*<
2293− toEncoding d >*<
2294− toEncoding e >*<
2295− toF f >*<
2296− toG g
2283+ liftToEncoding2 toF _ toG _ (a, b, c, d, e, f, g) = E.list id
2284+ [ toEncoding a
2285+ , toEncoding b
2286+ , toEncoding c
2287+ , toEncoding d
2288+ , toEncoding e
2289+ , toF f
2290+ , toG g
2291+ ]
22972292 {-# INLINE liftToEncoding2 #-}
22982293
22992294instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) where
@@ -2322,15 +2317,16 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON2
23222317 return mv
23232318 {-# INLINE liftToJSON2 #-}
23242319
2325− liftToEncoding2 toG _ toH _ (a, b, c, d, e, f, g, h) = tuple $
2326− toEncoding a >*<
2327− toEncoding b >*<
2328− toEncoding c >*<
2329− toEncoding d >*<
2330− toEncoding e >*<
2331− toEncoding f >*<
2332− toG g >*<
2333− toH h
2320+ liftToEncoding2 toG _ toH _ (a, b, c, d, e, f, g, h) = E.list id
2321+ [ toEncoding a
2322+ , toEncoding b
2323+ , toEncoding c
2324+ , toEncoding d
2325+ , toEncoding e
2326+ , toEncoding f
2327+ , toG g
2328+ , toH h
2329+ ]
23342330 {-# INLINE liftToEncoding2 #-}
23352331
23362332instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) where
@@ -2360,16 +2356,17 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g)
23602356 return mv
23612357 {-# INLINE liftToJSON2 #-}
23622358
2363− liftToEncoding2 toH _ toI _ (a, b, c, d, e, f, g, h, i) = tuple $
2364− toEncoding a >*<
2365− toEncoding b >*<
2366− toEncoding c >*<
2367− toEncoding d >*<
2368− toEncoding e >*<
2369− toEncoding f >*<
2370− toEncoding g >*<
2371− toH h >*<
2372− toI i
2359+ liftToEncoding2 toH _ toI _ (a, b, c, d, e, f, g, h, i) = E.list id
2360+ [ toEncoding a
2361+ , toEncoding b
2362+ , toEncoding c
2363+ , toEncoding d
2364+ , toEncoding e
2365+ , toEncoding f
2366+ , toEncoding g
2367+ , toH h
2368+ , toI i
2369+ ]
23732370 {-# INLINE liftToEncoding2 #-}
23742371
23752372instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON1 ((,,,,,,,,) a b c d e f g h) where
@@ -2400,17 +2397,18 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
24002397 return mv
24012398 {-# INLINE liftToJSON2 #-}
24022399
2403− liftToEncoding2 toI _ toJ _ (a, b, c, d, e, f, g, h, i, j) = tuple $
2404− toEncoding a >*<
2405− toEncoding b >*<
2406− toEncoding c >*<
2407− toEncoding d >*<
2408− toEncoding e >*<
2409− toEncoding f >*<
2410− toEncoding g >*<
2411− toEncoding h >*<
2412− toI i >*<
2413− toJ j
2400+ liftToEncoding2 toI _ toJ _ (a, b, c, d, e, f, g, h, i, j) = E.list id
2401+ [ toEncoding a
2402+ , toEncoding b
2403+ , toEncoding c
2404+ , toEncoding d
2405+ , toEncoding e
2406+ , toEncoding f
2407+ , toEncoding g
2408+ , toEncoding h
2409+ , toI i
2410+ , toJ j
2411+ ]
24142412 {-# INLINE liftToEncoding2 #-}
24152413
24162414instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON1 ((,,,,,,,,,) a b c d e f g h i) where
@@ -2442,18 +2440,19 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
24422440 return mv
24432441 {-# INLINE liftToJSON2 #-}
24442442
2445− liftToEncoding2 toJ _ toK _ (a, b, c, d, e, f, g, h, i, j, k) = tuple $
2446− toEncoding a >*<
2447− toEncoding b >*<
2448− toEncoding c >*<
2449− toEncoding d >*<
2450− toEncoding e >*<
2451− toEncoding f >*<
2452− toEncoding g >*<
2453− toEncoding h >*<
2454− toEncoding i >*<
2455− toJ j >*<
2456− toK k
2443+ liftToEncoding2 toJ _ toK _ (a, b, c, d, e, f, g, h, i, j, k) = E.list id
2444+ [ toEncoding a
2445+ , toEncoding b
2446+ , toEncoding c
2447+ , toEncoding d
2448+ , toEncoding e
2449+ , toEncoding f
2450+ , toEncoding g
2451+ , toEncoding h
2452+ , toEncoding i
2453+ , toJ j
2454+ , toK k
2455+ ]
24572456 {-# INLINE liftToEncoding2 #-}
24582457
24592458instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON1 ((,,,,,,,,,,) a b c d e f g h i j) where
@@ -2486,19 +2485,20 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
24862485 return mv
24872486 {-# INLINE liftToJSON2 #-}
24882487
2489− liftToEncoding2 toK _ toL _ (a, b, c, d, e, f, g, h, i, j, k, l) = tuple $
2490− toEncoding a >*<
2491− toEncoding b >*<
2492− toEncoding c >*<
2493− toEncoding d >*<
2494− toEncoding e >*<
2495− toEncoding f >*<
2496− toEncoding g >*<
2497− toEncoding h >*<
2498− toEncoding i >*<
2499− toEncoding j >*<
2500− toK k >*<
2501− toL l
2488+ liftToEncoding2 toK _ toL _ (a, b, c, d, e, f, g, h, i, j, k, l) = E.list id
2489+ [ toEncoding a
2490+ , toEncoding b
2491+ , toEncoding c
2492+ , toEncoding d
2493+ , toEncoding e
2494+ , toEncoding f
2495+ , toEncoding g
2496+ , toEncoding h
2497+ , toEncoding i
2498+ , toEncoding j
2499+ , toK k
2500+ , toL l
2501+ ]
25022502 {-# INLINE liftToEncoding2 #-}
25032503
25042504instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) where
@@ -2532,20 +2532,21 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
25322532 return mv
25332533 {-# INLINE liftToJSON2 #-}
25342534
2535− liftToEncoding2 toL _ toM _ (a, b, c, d, e, f, g, h, i, j, k, l, m) = tuple $
2536− toEncoding a >*<
2537− toEncoding b >*<
2538− toEncoding c >*<
2539− toEncoding d >*<
2540− toEncoding e >*<
2541− toEncoding f >*<
2542− toEncoding g >*<
2543− toEncoding h >*<
2544− toEncoding i >*<
2545− toEncoding j >*<
2546− toEncoding k >*<
2547− toL l >*<
2548− toM m
2535+ liftToEncoding2 toL _ toM _ (a, b, c, d, e, f, g, h, i, j, k, l, m) = E.list id
2536+ [ toEncoding a
2537+ , toEncoding b
2538+ , toEncoding c
2539+ , toEncoding d
2540+ , toEncoding e
2541+ , toEncoding f
2542+ , toEncoding g
2543+ , toEncoding h
2544+ , toEncoding i
2545+ , toEncoding j
2546+ , toEncoding k
2547+ , toL l
2548+ , toM m
2549+ ]
25492550 {-# INLINE liftToEncoding2 #-}
25502551
25512552instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) where
@@ -2580,21 +2581,22 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
25802581 return mv
25812582 {-# INLINE liftToJSON2 #-}
25822583
2583− liftToEncoding2 toM _ toN _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = tuple $
2584− toEncoding a >*<
2585− toEncoding b >*<
2586− toEncoding c >*<
2587− toEncoding d >*<
2588− toEncoding e >*<
2589− toEncoding f >*<
2590− toEncoding g >*<
2591− toEncoding h >*<
2592− toEncoding i >*<
2593− toEncoding j >*<
2594− toEncoding k >*<
2595− toEncoding l >*<
2596− toM m >*<
2597− toN n
2584+ liftToEncoding2 toM _ toN _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = E.list id
2585+ [ toEncoding a
2586+ , toEncoding b
2587+ , toEncoding c
2588+ , toEncoding d
2589+ , toEncoding e
2590+ , toEncoding f
2591+ , toEncoding g
2592+ , toEncoding h
2593+ , toEncoding i
2594+ , toEncoding j
2595+ , toEncoding k
2596+ , toEncoding l
2597+ , toM m
2598+ , toN n
2599+ ]
25982600 {-# INLINE liftToEncoding2 #-}
25992601
26002602instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
@@ -2630,22 +2632,23 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
26302632 return mv
26312633 {-# INLINE liftToJSON2 #-}
26322634
2633− liftToEncoding2 toN _ toO _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = tuple $
2634− toEncoding a >*<
2635− toEncoding b >*<
2636− toEncoding c >*<
2637− toEncoding d >*<
2638− toEncoding e >*<
2639− toEncoding f >*<
2640− toEncoding g >*<
2641− toEncoding h >*<
2642− toEncoding i >*<
2643− toEncoding j >*<
2644− toEncoding k >*<
2645− toEncoding l >*<
2646− toEncoding m >*<
2647− toN n >*<
2648− toO o
2635+ liftToEncoding2 toN _ toO _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = E.list id
2636+ [ toEncoding a
2637+ , toEncoding b
2638+ , toEncoding c
2639+ , toEncoding d
2640+ , toEncoding e
2641+ , toEncoding f
2642+ , toEncoding g
2643+ , toEncoding h
2644+ , toEncoding i
2645+ , toEncoding j
2646+ , toEncoding k
2647+ , toEncoding l
2648+ , toEncoding m
2649+ , toN n
2650+ , toO o
2651+ ]
26492652 {-# INLINE liftToEncoding2 #-}
26502653
26512654instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) where
aeson.cabal+11−1
@@ -58,6 +58,11 @@ flag developer
5858 default: False
5959 manual: True
6060
61+flag fast
62+ description: compile without optimizations
63+ default: False
64+ manual: True
65+
6166flag bytestring-builder
6267 description: Depend on the bytestring-builder package for backwards compatibility.
6368 default: False
@@ -129,11 +134,16 @@ library
129134 -- `Numeric.Natural` is available in base only since GHC 7.10 / base 4.8
130135 build-depends: nats >= 1 && < 1.2
131136
137+ ghc-options: -Wall
138+
132139 if flag(developer)
133140 ghc-options: -Werror
134141 ghc-prof-options: -auto-all
135142
136− ghc-options: -O2 -Wall
143+ if flag(fast)
144+ ghc-options: -O0
145+ else
146+ ghc-options: -O2
137147
138148 include-dirs: include
139149
benchmarks/AesonCompareAutoInstances.hs+12−14
@@ -1,24 +1,22 @@
1−{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, TemplateHaskell #-}
1+{-# LANGUAGE DeriveDataTypeable #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE TemplateHaskell #-}
24
3−module Main where
5+module Main (main) where
46
5−--------------------------------------------------------------------------------
6−
7−import Criterion.Main hiding (defaultOptions)
7+import Prelude ()
8+import Prelude.Compat
89
910import Control.DeepSeq (NFData, rnf, deepseq)
10−
11−import Data.Typeable (Typeable)
11+import Criterion.Main hiding (defaultOptions)
12+import Data.Aeson.Encode
13+import Data.Aeson.TH
14+import Data.Aeson.Types
1215import Data.Data (Data)
16+import Data.Typeable (Typeable)
1317import GHC.Generics (Generic)
14−
15−import Data.Aeson.Types
16−import Data.Aeson.TH
17−import qualified Data.Aeson.Generic as G (fromJSON, toJSON)
18−
19−import Data.Aeson.Encode
20−
2118import Options
19+import qualified Data.Aeson.Generic as G (fromJSON, toJSON)
2220
2321--------------------------------------------------------------------------------
2422
benchmarks/AesonEncode.hs+9−2
@@ -1,5 +1,12 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE OverloadedStrings #-}
23
4+module Main (main) where
5+
6+import Prelude ()
7+import Prelude.Compat
8+
9+import Control.DeepSeq
310import Control.Exception
411import Control.Monad
512import Data.Aeson
@@ -9,7 +16,6 @@ import Data.Time.Clock
916import System.Environment (getArgs)
1017import System.IO
1118import qualified Data.ByteString as B
12−import Control.DeepSeq
1319
1420main :: IO ()
1521main = do
@@ -17,6 +23,7 @@ main = do
1723 let (cnt,args) = case args0 of
1824 (i:c:a) | all isDigit i && all isDigit c -> (c,a)
1925 (c:a) -> (c,a)
26+ [] -> error "Unexpected empty list"
2027 let count = read cnt :: Int
2128 forM_ args $ \arg -> bracket (openFile arg ReadMode) hClose $ \h -> do
2229 putStrLn $ arg ++ ":"
benchmarks/AesonFoldable.hs+9−4
@@ -1,11 +1,16 @@
1−{-# LANGUAGE OverloadedStrings, PackageImports #-}
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE PackageImports #-}
3+
4+module Main (main) where
5+
26import Criterion.Main
37
4−import qualified "aeson" Data.Aeson as A
5−import qualified "aeson-benchmarks" Data.Aeson as B
8+import Prelude ()
9+import Prelude.Compat
610
711import Data.Foldable (toList)
8−
12+import qualified "aeson" Data.Aeson as A
13+import qualified "aeson-benchmarks" Data.Aeson as B
914import qualified Data.Sequence as S
1015import qualified Data.Vector as V
1116import qualified Data.Vector.Unboxed as U
benchmarks/AesonMap.hs+15−7
@@ -1,19 +1,27 @@
1−{-# LANGUAGE OverloadedStrings, RankNTypes, PackageImports, FlexibleContexts #-}
1+{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE PackageImports #-}
4+{-# LANGUAGE RankNTypes #-}
5+
6+{-# OPTIONS_GHC -fno-warn-orphans #-}
7+
8+module Main (main) where
9+
10+import Prelude ()
11+import Prelude.Compat
212
313import Control.DeepSeq
414import Criterion.Main
515import Data.Hashable
616import Data.Proxy (Proxy (..))
717import Data.Tagged (Tagged (..))
8−import qualified Data.ByteString.Lazy as LBS
9−import qualified Data.Text as T
10−import qualified Data.Map as M
11−import qualified Data.HashMap.Strict as HM
12−
1318import qualified "aeson" Data.Aeson as A
14−
1519import qualified "aeson-benchmarks" Data.Aeson as B
1620import qualified "aeson-benchmarks" Data.Aeson.Types as B (fromJSONKeyCoerce)
21+import qualified Data.ByteString.Lazy as LBS
22+import qualified Data.HashMap.Strict as HM
23+import qualified Data.Map as M
24+import qualified Data.Text as T
1725
1826value :: Int -> HM.HashMap T.Text T.Text
1927value n = HM.fromList $ map f [1..n]
benchmarks/AesonParse.hs+8−2
@@ -1,9 +1,15 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE PackageImports #-}
34
5+module Main (main) where
6+
7+import Prelude ()
8+import Prelude.Compat
9+
10+import "aeson-benchmarks" Data.Aeson
411import Control.Exception
512import Control.Monad
6−import "aeson-benchmarks" Data.Aeson
713import Data.Attoparsec.ByteString (IResult(..), parseWith)
814import Data.Time.Clock
915import System.Environment (getArgs)
benchmarks/AesonTuples.hs+5−2
@@ -1,9 +1,12 @@
11module Main where
22
3−--------------------------------------------------------------------------------
3+module Main (main) where
4+
5+import Prelude ()
6+import Prelude.Compat
47
5−import Criterion.Main
68import Control.DeepSeq (deepseq)
9+import Criterion.Main
710import Data.Aeson
811
912--------------------------------------------------------------------------------
benchmarks/Compare.hs+5−2
@@ -1,8 +1,11 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21{-# LANGUAGE PackageImports #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
33
44module Main (main) where
55
6+import Prelude ()
7+import Prelude.Compat
8+
69import Compare.BufferBuilder ()
710import Compare.JsonBuilder ()
811import Criterion.Main
@@ -11,8 +14,8 @@ import Data.Json.Builder
1114import Twitter
1215import Twitter.Manual ()
1316import Typed.Common
14−import qualified Compare.JsonBench as JsonBench
1517import qualified "aeson-benchmarks" Data.Aeson as Aeson
18+import qualified Compare.JsonBench as JsonBench
1619
1720main :: IO ()
1821main =
benchmarks/Compare/BufferBuilder.hs+9−3
@@ -1,11 +1,17 @@
1−{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE RecordWildCards #-}
3+
4+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
25{-# OPTIONS_GHC -fno-warn-orphans #-}
36
47module Compare.BufferBuilder () where
58
9+import Prelude ()
10+import Prelude.Compat
11+
612import Data.BufferBuilder.Json
7−import Data.Monoid ((<>))
813import Data.Int (Int64)
14+import Data.Monoid ((<>))
915import Prelude hiding (id)
1016import Twitter
1117import qualified Data.BufferBuilder.Utf8 as UB
@@ -37,7 +43,7 @@ instance ToJson Story where
3743 <> "metadata" .= metadata
3844 <> "to_user_id" .= to_user_id
3945 <> "text" .= text
40− <> "id" .= id
46+ <> "id" .= id_
4147 <> "from_user_id" .= from_user_id
4248 <> "geo" .= geo
4349 <> "iso_language_code" .= iso_language_code
benchmarks/Compare/JsonBench.hs+8−2
@@ -2,12 +2,18 @@
22--
33-- https://github.com/chadaustin/buffer-builder/blob/master/test.json
44
5−{-# LANGUAGE BangPatterns, OverloadedStrings, RecordWildCards #-}
5+{-# LANGUAGE BangPatterns #-}
66{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7−{-# LANGUAGE MagicHash, ScopedTypeVariables #-}
7+{-# LANGUAGE MagicHash #-}
8+{-# LANGUAGE OverloadedStrings #-}
9+{-# LANGUAGE RecordWildCards #-}
10+{-# LANGUAGE ScopedTypeVariables #-}
811
912module Compare.JsonBench (benchmarks) where
1013
14+import Prelude ()
15+import Prelude.Compat
16+
1117import Control.DeepSeq (NFData(..))
1218import Criterion
1319import Data.Aeson ((.:))
benchmarks/Compare/JsonBuilder.hs+6−1
@@ -1,8 +1,13 @@
11{-# LANGUAGE RecordWildCards #-}
2+
3+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
24{-# OPTIONS_GHC -fno-warn-orphans #-}
35
46module Compare.JsonBuilder () where
57
8+import Prelude ()
9+import Prelude.Compat
10+
611import Data.Json.Builder
712import Data.Monoid ((<>))
813import Prelude hiding (id)
@@ -36,7 +41,7 @@ instance JsObject Story where
3641 row "metadata" metadata <>
3742 row "to_user_id" to_user_id <>
3843 row "text" text <>
39− row "id" id <>
44+ row "id" id_ <>
4045 row "from_user_id" from_user_id <>
4146 row "geo" geo <>
4247 row "iso_language_code" iso_language_code <>
benchmarks/CompareWithJSON.hs+6−1
@@ -1,5 +1,10 @@
11{-# OPTIONS_GHC -fno-warn-orphans #-}
22
3+module Main (main) where
4+
5+import Prelude ()
6+import Prelude.Compat
7+
38import Blaze.ByteString.Builder (toLazyByteString)
49import Blaze.ByteString.Builder.Char.Utf8 (fromString)
510import Control.DeepSeq (NFData(rnf))
@@ -7,10 +12,10 @@ import Criterion.Main
712import qualified Data.Aeson as A
813import qualified Data.Aeson.Text as A
914import qualified Data.ByteString.Lazy as BL
10−import qualified Text.JSON as J
1115import qualified Data.Text.Lazy as TL
1216import qualified Data.Text.Lazy.Builder as TLB
1317import qualified Data.Text.Lazy.Encoding as TLE
18+import qualified Text.JSON as J
1419
1520instance (NFData v) => NFData (J.JSObject v) where
1621 rnf o = rnf (J.fromJSObject o)
benchmarks/Dates.hs+5−1
@@ -1,4 +1,8 @@
1−import Control.Applicative ((<$>))
1+module Main (main) where
2+
3+import Prelude ()
4+import Prelude.Compat
5+
26import Criterion.Main
37import Data.Aeson (decode, encode)
48import Data.Time.Clock (UTCTime)
benchmarks/JsonParse.hs+8−2
@@ -1,11 +1,17 @@
1−{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
23{-# OPTIONS_GHC -fno-warn-orphans #-}
34
5+module Main (main) where
6+
7+import Prelude ()
8+import Prelude.Compat
9+
410import Control.DeepSeq
511import Control.Monad
6−import Text.JSON
712import Data.Time.Clock
813import System.Environment (getArgs)
14+import Text.JSON
915
1016instance NFData JSValue where
1117 rnf JSNull = ()
benchmarks/Micro.hs+3−1
@@ -1,11 +1,13 @@
11module Main (main) where
22
3+import Prelude ()
4+import Prelude.Compat
5+
36import Criterion.Main
47import qualified Data.Aeson.Encoding.Builder as AB
58import qualified Data.ByteString.Builder as B
69import qualified Data.Text as T
710
8−
911main :: IO ()
1012main = do
1113 let txt = "append (append b (primBounded w1 x1)) (primBounded w2 x2)"
benchmarks/Options.hs+4−1
@@ -1,4 +1,7 @@
1−module Options where
1+module Options () where
2+
3+import Prelude ()
4+import Prelude.Compat
25
36import Data.Aeson.Types
47
benchmarks/ReadFile.hs+7−1
@@ -1,4 +1,10 @@
1−{-# LANGUAGE BangPatterns, OverloadedStrings #-}
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+
4+module Main (main) where
5+
6+import Prelude ()
7+import Prelude.Compat
28
39import Control.DeepSeq
410import Control.Exception
benchmarks/Typed.hs+3
@@ -1,5 +1,8 @@
11module Main (main) where
22
3+import Prelude ()
4+import Prelude.Compat
5+
36import Criterion.Main
47import qualified Typed.Generic as Generic
58import qualified Typed.Manual as Manual
benchmarks/Typed/Common.hs+12−6
@@ -1,6 +1,17 @@
1−{-# LANGUAGE CPP, PackageImports #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE PackageImports #-}
3+
4+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
5+
26module Typed.Common (load) where
37
8+import Prelude ()
9+import Prelude.Compat
10+
11+import Data.ByteString.Lazy as L
12+import System.Exit
13+import System.IO
14+
415#ifndef HAS_BOTH_AESON_AND_BENCHMARKS
516import Data.Aeson hiding (Result)
617#else
@@ -8,11 +19,6 @@ import "aeson" Data.Aeson hiding (Result)
819import qualified "aeson-benchmarks" Data.Aeson as B
920#endif
1021
11−import Data.ByteString.Lazy as L
12−import Control.Applicative
13−import System.IO
14−import System.Exit
15−
1622load :: FromJSON a => FilePath -> IO a
1723load fileName = do
1824 mv <- eitherDecode' <$> L.readFile fileName
benchmarks/Typed/Generic.hs+4−3
@@ -1,14 +1,15 @@
11{-# LANGUAGE PackageImports #-}
22module Typed.Generic (benchmarks) where
33
4−import "aeson" Data.Aeson hiding (Result)
5−import qualified "aeson-benchmarks" Data.Aeson as B
4+import Prelude ()
5+import Prelude.Compat
66
7−import Control.Applicative
7+import "aeson" Data.Aeson hiding (Result)
88import Criterion
99import Data.ByteString.Lazy as L
1010import Twitter.TH
1111import Typed.Common
12+import qualified "aeson-benchmarks" Data.Aeson as B
1213
1314encodeDirectA :: Result -> L.ByteString
1415encodeDirectA = encode
benchmarks/Typed/Manual.hs+4−3
@@ -1,14 +1,15 @@
11{-# LANGUAGE PackageImports #-}
22module Typed.Manual (benchmarks) where
33
4−import "aeson" Data.Aeson hiding (Result)
5−import qualified "aeson-benchmarks" Data.Aeson as B
4+import Prelude ()
5+import Prelude.Compat
66
7−import Control.Applicative
7+import "aeson" Data.Aeson hiding (Result)
88import Criterion
99import Data.ByteString.Lazy as L
1010import Twitter.Manual
1111import Typed.Common
12+import qualified "aeson-benchmarks" Data.Aeson as B
1213
1314encodeDirectA :: Result -> L.ByteString
1415encodeDirectA = encode
benchmarks/Typed/TH.hs+4−4
@@ -1,15 +1,15 @@
11{-# LANGUAGE PackageImports #-}
22module Typed.TH (benchmarks) where
33
4−import "aeson" Data.Aeson hiding (Result)
5−import qualified "aeson-benchmarks" Data.Aeson as B
4+import Prelude ()
5+import Prelude.Compat
66
7−import Control.Applicative
7+import "aeson" Data.Aeson hiding (Result)
88import Criterion
9−import Data.ByteString.Builder as B
109import Data.ByteString.Lazy as L
1110import Twitter.TH
1211import Typed.Common
12+import qualified "aeson-benchmarks" Data.Aeson as B
1313
1414encodeDirectA :: Result -> L.ByteString
1515encodeDirectA = encode
benchmarks/aeson-benchmarks.cabal+11−1
@@ -81,6 +81,7 @@ executable aeson-benchmark-compare
8181 build-depends:
8282 aeson-benchmarks,
8383 base,
84+ base-compat,
8485 buffer-builder,
8586 bytestring,
8687 criterion >= 1.0,
@@ -96,6 +97,7 @@ executable aeson-benchmark-micro
9697 build-depends:
9798 aeson-benchmarks,
9899 base,
100+ base-compat,
99101 bytestring,
100102 criterion >= 1.0,
101103 deepseq,
@@ -113,6 +115,7 @@ executable aeson-benchmark-typed
113115 aeson,
114116 aeson-benchmarks,
115117 base,
118+ base-compat,
116119 criterion >= 1.0,
117120 deepseq,
118121 ghc-prim,
@@ -131,6 +134,7 @@ executable aeson-benchmark-compare-with-json
131134 build-depends:
132135 aeson-benchmarks,
133136 base,
137+ base-compat,
134138 blaze-builder,
135139 bytestring,
136140 criterion,
@@ -145,6 +149,7 @@ executable aeson-benchmark-aeson-encode
145149 aeson-benchmarks,
146150 attoparsec,
147151 base,
152+ base-compat,
148153 bytestring,
149154 deepseq,
150155 time
@@ -156,6 +161,7 @@ executable aeson-benchmark-aeson-parse
156161 aeson-benchmarks,
157162 attoparsec,
158163 base,
164+ base-compat,
159165 bytestring,
160166 time
161167
@@ -164,6 +170,7 @@ executable aeson-benchmark-json-parse
164170 ghc-options: -Wall -O2 -rtsopts
165171 build-depends:
166172 base,
173+ base-compat,
167174 deepseq,
168175 json,
169176 time
@@ -173,6 +180,7 @@ executable aeson-benchmark-dates
173180 ghc-options: -Wall -O2 -rtsopts
174181 build-depends:
175182 base,
183+ base-compat,
176184 bytestring,
177185 criterion,
178186 deepseq,
@@ -184,9 +192,10 @@ executable aeson-benchmark-map
184192 main-is: AesonMap.hs
185193 ghc-options: -Wall -O2 -rtsopts
186194 build-depends:
187− aeson == 0.11.*,
195+ aeson,
188196 aeson-benchmarks,
189197 base,
198+ base-compat,
190199 criterion >= 1.0,
191200 bytestring,
192201 containers,
@@ -203,6 +212,7 @@ executable aeson-benchmark-foldable
203212 aeson,
204213 aeson-benchmarks,
205214 base,
215+ base-compat,
206216 criterion >= 1.0,
207217 bytestring,
208218 containers,
changelog.md+51−25
@@ -2,52 +2,78 @@ For the latest version of this document, please see [https://github.com/bos/aeso
22
33# 1.0.0.0
44
5−* Added list specific members to `ToJSON` and `FromJSON` classes. In the same
6− way `Read` / `Show` handle lists specifically. This removes need for
7− overlapping instances to handle `String`.
5+Major enhancements:
86
9−* Added higher rank classes: `ToJSON1`, `ToJSON2`, `FromJSON1`, and `FromJSON2`.
7+* Introduced new `FromJSONKey` and `ToJSONKey` type classes that are
8+ used to encode maps without going through HashMap
109
11−* Modified instances for `Map` and `HashMap`. Introduced new `FromJSONKey` and
12− `ToJSONKey` type classes.
10+* Added higher rank classes: `ToJSON1`, `ToJSON2`, `FromJSON1`, and
11+ `FromJSON2`.
1312
14−* Integral `FromJSON` instances do not accept non integral JSON numbers (e.g. `3.14`).
15− Also over/underflows are caught for bounded types.
13+* Added `Data.Aeson.Encoding` with functions to safely write `ToJSON`
14+ instances using `toEncoding`.
1615
17−* Added `Data.Aeson.Encoding` with functions to work with `Encoding` in an abstract way.
16+Other enhancements:
1817
19−* Added `UntaggedValue` to `SumEncoding`
18+* A Cabal `fast` flag was added to disable building with optimizations. This drastically speeds up compiling both aeson ***and*** libraries using aeson so it is recommended to enable it during development. With cabal-install you can `cabal install aeson -ffast` and with stack you can add a flag section to your stack.yaml:
19+```
20+flags:
21+ aeson:
22+ fast: true
23+```
2024
21−* Export `decodeWith`, `decodeStrictWith`, `eitherDecodeWith`, and
22− `eitherDecodeStrictWith` from `Data.Aeson.Parser`. This allows
23− decoding using explicit parsers instead of using `FromJSON`
24− instances.
25+* Added list specific members to `ToJSON` and `FromJSON` classes. In
26+ the same way `Read` and `Show` handle lists specifically. This
27+ removes need for overlapping instances to handle `String`.
2528
26−* Remove the `contents` field encoding with `allNullaryToStringTag = False`,
27− giving us `{ "tag" : "c1" }` instead of `{ "tag" : "c1", contents : [] }`.
28− The contents field is optional when parsing so this is only a breaking change for ToJSON.
29+* Added a new `sumEncoding` option `UntaggedValue` which prevents
30+ objects from being tagged with the constructor name.
2931
30−* Fix a bug where `genericToEncoding` with `unwrapUnaryRecords = True`
31− would produce an invalid encoding: `"unwrap\":""`.
32+* JSONPaths are now tracked in instances derived with template-haskell
33+ and generics.
3234
3335* Get rid of redundancy of JSONPath error messages in nested records.
3436
3537 `eitherDecode "{\"x\":{\"a\": [1,2,true]}}" :: Either String Y`
36− previously yielded `Error in $.x.a[2]: failed to parse field" x:
37− failed to parse field a: expected Int, encountered Boolean` and now
38− yields `Error in $.x.a[2]: expected Int, encountered Boolean"`.
38+ previously yielded
39+ `Error in $.x.a[2]: failed to parse field" x: failed to parse field a: expected Int, encountered Boolean`
40+ and now yields `Error in $.x.a[2]: expected Int, encountered Boolean"`.
3941
4042 Some users might prefer to insert `modifyFailure` themselves to
4143 customize error messages, which previously prevented the use of
4244 `(.:)`.
4345
46+* Backwards compatibility with `bytestring-0.9` using the
47+ `bytestring-builder` compatibility package.
48+
49+* Export `decodeWith`, `decodeStrictWith`, `eitherDecodeWith`, and
50+ `eitherDecodeStrictWith` from `Data.Aeson.Parser`. This allows
51+ decoding using explicit parsers instead of using `FromJSON`
52+ instances.
53+
54+* Un-orphan internal instances to render them in haddocks.
55+
56+Other changes:
57+
58+* Integral `FromJSON` instances now only accept integral
59+ values. E.g. parsing `3.14` to `Int` fails instead of succeeding
60+ with the value `3`.
61+
62+* Over/underflows are now caught for bounded numeric types.
63+
64+* Remove the `contents` field encoding with `allNullaryToStringTag = False`,
65+ giving us `{ "tag" : "c1" }` instead of `{ "tag" : "c1", contents : [] }`.
66+ The contents field is optional when parsing so this is only a breaking
67+ change for ToJSON instances.
68+
69+* Fix a bug where `genericToEncoding` with `unwrapUnaryRecords = True`
70+ would produce an invalid encoding: `"unwrap\":""`.
71+
4472* `ToJSON` instances using `genericToEncoding` and `omitNothingFields`
45− no longer produces invalid JSON.
73+ no longer produce invalid JSON.
4674
4775* Added instances for `DList`, `Compose`, `Product`, `Sum`.
4876
49−* Buildable with `bytestring-0.9` (with a help of `bytestring-builder` compatibility package).
50−
5177### 0.11.2.0
5278
5379* Enable `PolyKinds` to generalize `Proxy`, `Tagged`, and `Const` instances.
examples/Generic.hs+7−5
@@ -6,17 +6,19 @@
66-- automatically derive the Generic class for us.
77
88{-# LANGUAGE DeriveGeneric #-}
9−
109{-# LANGUAGE OverloadedStrings #-}
1110
11+module Main (main) where
12+
13+import Prelude ()
14+import Prelude.Compat
15+
1216import Data.Aeson (FromJSON, ToJSON, decode, encode)
1317import qualified Data.ByteString.Lazy.Char8 as BL
18+import GHC.Generics (Generic)
1419
1520-- To decode or encode a value using the generic machinery, we must
1621-- make the type an instance of the Generic class.
17−
18−import GHC.Generics (Generic)
19−
2022data Coord = Coord { x :: Double, y :: Double }
2123 deriving (Show, Generic)
2224
@@ -31,5 +33,5 @@ main :: IO ()
3133main = do
3234 let req = decode "{\"x\":3.0,\"y\":-1.0}" :: Maybe Coord
3335 print req
34− let reply = Coord 123.4 20
36+ let reply = Coord { x = 123.4, y = 20 }
3537 BL.putStrLn (encode reply)
examples/Simplest.hs+8−2
@@ -1,6 +1,12 @@
1−{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE RecordWildCards #-}
23
3−import Control.Applicative ((<$>), (<*>), empty)
4+module Main (main) where
5+
6+import Prelude ()
7+import Prelude.Compat
8+
9+import Control.Applicative (empty)
410import Data.Aeson
511import Data.Monoid
612import qualified Data.ByteString.Lazy.Char8 as BL
examples/TemplateHaskell.hs+6−3
@@ -1,10 +1,13 @@
11-- We can use Template Haskell (TH) to generate instances of the
22-- FromJSON and ToJSON classes automatically. This is the fastest way
33-- to add JSON support for a type.
4−
4+{-# LANGUAGE OverloadedStrings #-}
55{-# LANGUAGE TemplateHaskell #-}
66
7−{-# LANGUAGE OverloadedStrings #-}
7+module Main (main) where
8+
9+import Prelude ()
10+import Prelude.Compat
811
912import Data.Aeson (decode, encode)
1013import Data.Aeson.TH (deriveJSON, defaultOptions)
@@ -21,5 +24,5 @@ main :: IO ()
2124main = do
2225 let req = decode "{\"x\":3.0,\"y\":-1.0}" :: Maybe Coord
2326 print req
24− let reply = Coord 123.4 20
27+ let reply = Coord { x = 123.4, y = 20 }
2528 BL.putStrLn (encode reply)
examples/Twitter.hs+9−5
@@ -8,22 +8,26 @@
88-- renamed "type" to "type_" in the *.json files, to avoid overlap
99-- with a Haskell reserved keyword.
1010
11−{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
11+{-# LANGUAGE DeriveDataTypeable #-}
12+{-# LANGUAGE DeriveGeneric #-}
1213
13−module Twitter (
14+module Twitter
15+ (
1416 Metadata(..)
1517 , Geo(..)
1618 , Story(..)
1719 , Result(..)
1820 ) where
1921
22+import Prelude ()
23+import Prelude.Compat
24+
25+import Control.DeepSeq
2026import Data.Data (Typeable, Data)
2127import Data.Int (Int64)
2228import Data.Text (Text)
23−-- import Data.Time (ZonedTime)
2429import GHC.Generics (Generic)
2530import Prelude hiding (id)
26−import Control.DeepSeq
2731
2832data Metadata = Metadata {
2933 result_type :: Text
@@ -47,7 +51,7 @@ data Story = Story {
4751 , metadata :: Metadata
4852 , to_user_id :: Maybe Int64
4953 , text :: Text
50− , id :: Int64
54+ , id_ :: Int64
5155 , from_user_id :: Int64
5256 , geo :: Maybe Geo
5357 , iso_language_code :: Text
examples/Twitter/Generic.hs+5−2
@@ -1,6 +1,6 @@
11-- Use GHC generics to automatically generate good instances.
2−
3−{-# LANGUAGE CPP, PackageImports #-}
2+{-# LANGUAGE CPP #-}
3+{-# LANGUAGE PackageImports #-}
44{-# OPTIONS_GHC -fno-warn-orphans #-}
55
66module Twitter.Generic
@@ -11,6 +11,9 @@ module Twitter.Generic
1111 , Result(..)
1212 ) where
1313
14+import Prelude ()
15+import Prelude.Compat
16+
1417import Twitter
1518
1619#ifndef HAS_BOTH_AESON_AND_BENCHMARKS
examples/Twitter/Manual.hs+11−6
@@ -1,7 +1,9 @@
11-- Manually write instances.
22
3−{-# LANGUAGE CPP, PackageImports #-}
4−{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
3+{-# LANGUAGE CPP #-}
4+{-# LANGUAGE PackageImports #-}
5+{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE RecordWildCards #-}
57{-# OPTIONS_GHC -fno-warn-orphans #-}
68
79module Twitter.Manual
@@ -12,6 +14,9 @@ module Twitter.Manual
1214 , Result(..)
1315 ) where
1416
17+import Prelude ()
18+import Prelude.Compat
19+
1520import Control.Applicative
1621import Data.Monoid ((<>))
1722import Prelude hiding (id)
@@ -63,7 +68,7 @@ instance ToJSON Story where
6368 , "metadata" .= metadata
6469 , "to_user_id" .= to_user_id
6570 , "text" .= text
66− , "id" .= id
71+ , "id" .= id_
6772 , "from_user_id" .= from_user_id
6873 , "geo" .= geo
6974 , "iso_language_code" .= iso_language_code
@@ -80,7 +85,7 @@ instance ToJSON Story where
8085 <> "metadata" .= metadata
8186 <> "to_user_id" .= to_user_id
8287 <> "text" .= text
83− <> "id" .= id
88+ <> "id" .= id_
8489 <> "from_user_id" .= from_user_id
8590 <> "geo" .= geo
8691 <> "iso_language_code" .= iso_language_code
@@ -187,7 +192,7 @@ instance B.ToJSON Story where
187192 , "metadata" B..= metadata
188193 , "to_user_id" B..= to_user_id
189194 , "text" B..= text
190− , "id" B..= id
195+ , "id" B..= id_
191196 , "from_user_id" B..= from_user_id
192197 , "geo" B..= geo
193198 , "iso_language_code" B..= iso_language_code
@@ -204,7 +209,7 @@ instance B.ToJSON Story where
204209 <> "metadata" B..= metadata
205210 <> "to_user_id" B..= to_user_id
206211 <> "text" B..= text
207− <> "id" B..= id
212+ <> "id" B..= id_
208213 <> "from_user_id" B..= from_user_id
209214 <> "geo" B..= geo
210215 <> "iso_language_code" B..= iso_language_code
examples/Twitter/TH.hs+5−1
@@ -1,6 +1,7 @@
11-- Use Template Haskell to generate good instances.
22
3−{-# LANGUAGE CPP, PackageImports #-}
3+{-# LANGUAGE CPP #-}
4+{-# LANGUAGE PackageImports #-}
45{-# LANGUAGE TemplateHaskell #-}
56{-# OPTIONS_GHC -fno-warn-orphans #-}
67
@@ -11,6 +12,9 @@ module Twitter.TH
1112 , Story(..)
1213 , Result(..)
1314 ) where
15+
16+import Prelude ()
17+
1418import Twitter
1519
1620#ifndef HAS_BOTH_AESON_AND_BENCHMARKS
examples/aeson-examples.cabal+3
@@ -9,6 +9,7 @@ executable aeson-example-generic
99 build-depends:
1010 aeson >= 0.10,
1111 base,
12+ base-compat,
1213 bytestring,
1314 ghc-prim
1415
@@ -18,6 +19,7 @@ executable aeson-example-simplest
1819 build-depends:
1920 aeson,
2021 base,
22+ base-compat,
2123 bytestring
2224
2325executable aeson-example-th
@@ -26,4 +28,5 @@ executable aeson-example-th
2628 build-depends:
2729 aeson,
2830 base,
31+ base-compat,
2932 bytestring
stack.yaml → stack-lts6.yamlrenamed+4−1
@@ -1,9 +1,12 @@
1−resolver: lts-6.7
1+resolver: lts-6.9
22packages:
33- '.'
44- benchmarks
5+- examples
56extra-deps:
67- semigroups-0.18.2
78flags:
9+ aeson:
10+ fast: true
811 semigroups:
912 bytestring-builder: false
stack-nightly.yamlnew file+12
@@ -0,0 +1,12 @@
1+resolver: nightly-2016-07-30
2+packages:
3+- '.'
4+- benchmarks
5+- examples
6+extra-deps:
7+- buffer-builder-0.2.4.3
8+- json-0.9.1
9+- json-builder-0.3
10+flags:
11+ aeson:
12+ fast: true
tests/DataFamilies/Encoders.hs+4−1
@@ -4,10 +4,13 @@
44
55module DataFamilies.Encoders where
66
7+import Prelude ()
8+import Prelude.Compat
9+
710import Data.Aeson.TH
811import Data.Aeson.Types
9−import Options
1012import DataFamilies.Types
13+import Options
1114
1215--------------------------------------------------------------------------------
1316-- Nullary encoders/decoders
tests/DataFamilies/Instances.hs+4−3
@@ -4,14 +4,15 @@
44{-# LANGUAGE TypeFamilies #-}
55{-# OPTIONS_GHC -fno-warn-orphans #-}
66
7−module DataFamilies.Instances where
7+module DataFamilies.Instances () where
8+
9+import Prelude ()
10+import Prelude.Compat
811
9−import Control.Applicative
1012import Data.Aeson.TH
1113import Data.Aeson.Types (FromJSON(..))
1214import DataFamilies.Types
1315import Test.QuickCheck (Arbitrary(..), elements, oneof)
14−import Prelude
1516
1617instance (Arbitrary a) => Arbitrary (Approx a) where
1718 arbitrary = Approx <$> arbitrary
tests/DataFamilies/Properties.hs+3−1
@@ -2,9 +2,11 @@
22
33module DataFamilies.Properties (tests) where
44
5+import Prelude ()
6+import Prelude.Compat
7+
58import DataFamilies.Encoders
69import DataFamilies.Instances ()
7−
810import Properties hiding (tests)
911
1012import Test.Framework (Test, testGroup)
tests/DataFamilies/Types.hs+4−1
@@ -1,15 +1,18 @@
11-- DataKinds is needed for deriveAll0 calls on GHC 8
22{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE DeriveGeneric #-}
34{-# LANGUAGE FlexibleInstances #-}
45{-# LANGUAGE GADTs #-}
56{-# LANGUAGE GeneralizedNewtypeDeriving #-}
67{-# LANGUAGE StandaloneDeriving #-}
7−{-# LANGUAGE DeriveGeneric #-}
88{-# LANGUAGE TemplateHaskell #-}
99{-# LANGUAGE TypeFamilies #-}
1010
1111module DataFamilies.Types where
1212
13+import Prelude ()
14+import Prelude.Compat
15+
1316import Generics.Deriving.TH (deriveAll0)
1417import Types (ApproxEq(..))
1518
tests/Encoders.hs+3
@@ -4,6 +4,9 @@
44
55module Encoders where
66
7+import Prelude ()
8+import Prelude.Compat
9+
710import Data.Aeson.TH
811import Data.Aeson.Types
912import Options
tests/Functions.hs+8−1
@@ -1,4 +1,11 @@
1−module Functions where
1+module Functions
2+ (
3+ approxEq
4+ , approxEqWith
5+ ) where
6+
7+import Prelude ()
8+import Prelude.Compat
29
310approxEq :: (Fractional a, Ord a) => a -> a -> Bool
411approxEq = approxEqWith 1e-15 1e-15
tests/Instances.hs+13−14
@@ -1,32 +1,31 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE FlexibleInstances #-}
32{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleInstances #-}
44{-# LANGUAGE OverloadedStrings #-}
55{-# LANGUAGE RecordWildCards #-}
66{-# LANGUAGE StandaloneDeriving #-}
77{-# OPTIONS_GHC -fno-warn-orphans #-}
88
9−module Instances where
9+module Instances () where
1010
1111import Prelude ()
1212import Prelude.Compat
1313
14−import Types
15−import Data.Function (on)
14+import Control.Applicative (Const(..), empty)
1615import Control.Monad
17−import Test.QuickCheck (Arbitrary(..), getNonNegative, elements,
18− listOf1, oneof, resize)
19−import Data.Time.Clock (UTCTime(..))
20−import Data.Time (ZonedTime(..), TimeZone(..))
21−import Data.List.NonEmpty (NonEmpty(..))
22−import Data.Version
2316import Data.Aeson.Types
24−import Control.Applicative (Const(..), empty)
25−import Data.Tagged (Tagged(..))
26−import Data.Proxy (Proxy(..))
27−import Data.Functor.Identity (Identity (..))
17+import Data.Function (on)
2818import Data.Functor.Compose (Compose (..))
19+import Data.Functor.Identity (Identity (..))
20+import Data.List.NonEmpty (NonEmpty(..))
21+import Data.Proxy (Proxy(..))
22+import Data.Tagged (Tagged(..))
23+import Data.Time (ZonedTime(..), TimeZone(..))
24+import Data.Time.Clock (UTCTime(..))
25+import Data.Version
2926import Functions
27+import Test.QuickCheck (Arbitrary(..), getNonNegative, elements, listOf1, oneof, resize)
28+import Types
3029import qualified Data.DList as DList
3130import qualified Data.HashMap.Strict as HM
3231
tests/Options.hs+3
@@ -1,5 +1,8 @@
11module Options where
22
3+import Prelude ()
4+import Prelude.Compat
5+
36import Data.Aeson.Types
47import Data.Char
58
tests/Properties.hs+13−13
@@ -1,7 +1,8 @@
1−{-# LANGUAGE CPP, OverloadedStrings, ScopedTypeVariables, RankNTypes #-}
2−
3−-- For Arbitrary Compose
4−{-# LANGUAGE FlexibleContexts #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE FlexibleContexts #-} -- For arbitrary Compose
3+{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE RankNTypes #-}
5+{-# LANGUAGE ScopedTypeVariables #-}
56
67module Properties where
78
@@ -10,23 +11,22 @@ import Prelude.Compat
1011
1112import Control.Applicative (Const)
1213import Data.Aeson (eitherDecode, encode)
14+import Data.Aeson.Encoding (encodingToLazyByteString)
1315import Data.Aeson.Internal (IResult(..), formatError, ifromJSON, iparse)
1416import Data.Aeson.Parser (value)
15−import Data.Aeson.Encoding (encodingToLazyByteString)
1617import Data.Aeson.Types
17−import Data.Int (Int8)
18−import Data.Sequence (Seq)
1918import Data.DList (DList)
20−import Data.Hashable (Hashable)
21−import Data.HashMap.Strict (HashMap)
2219import Data.Functor.Compose (Compose (..))
23−import Data.Map (Map)
24−import Data.Ratio (Ratio)
20+import Data.HashMap.Strict (HashMap)
21+import Data.Hashable (Hashable)
22+import Data.Int (Int8)
2523import Data.List.NonEmpty (NonEmpty)
26−import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
27− ZonedTime)
24+import Data.Map (Map)
2825import Data.Proxy (Proxy)
26+import Data.Ratio (Ratio)
27+import Data.Sequence (Seq)
2928import Data.Tagged (Tagged)
29+import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime, ZonedTime)
3030import Data.Version (Version)
3131import Encoders
3232import Instances ()
tests/Tests.hs+3
@@ -1,5 +1,8 @@
11module Main (main) where
22
3+import Prelude ()
4+import Prelude.Compat
5+
36import Test.Framework (defaultMain)
47import qualified DataFamilies.Properties as DF
58import qualified Properties
tests/Types.hs+6−3
@@ -8,13 +8,16 @@
88
99module Types where
1010
11−import qualified Data.Map as Map
11+import Prelude ()
12+import Prelude.Compat
13+
1214import Data.Data
15+import Data.Functor.Compose (Compose (..))
16+import Data.Functor.Identity (Identity (..))
1317import Data.Text
1418import GHC.Generics
1519import Test.QuickCheck (Property, counterexample)
16−import Data.Functor.Compose (Compose (..))
17−import Data.Functor.Identity (Identity (..))
20+import qualified Data.Map as Map
1821
1922type I = Identity
2023type Compose3 f g h = Compose (Compose f g) h
tests/UnitTests.hs+28−20
@@ -1,54 +1,58 @@
1−{-# LANGUAGE CPP, GADTs, DeriveGeneric, OverloadedStrings, ScopedTypeVariables, TemplateHaskell, GeneralizedNewtypeDeriving #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE GADTs #-}
4+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE ScopedTypeVariables #-}
7+{-# LANGUAGE TemplateHaskell #-}
28#if __GLASGOW_HASKELL__ >= 708
39{-# LANGUAGE DataKinds #-}
410#endif
511
612{-# OPTIONS_GHC -fno-warn-deprecations #-}
713
8−module UnitTests (ioTests, tests) where
14+module UnitTests
15+ (
16+ ioTests
17+ , tests
18+ ) where
919
1020import Prelude ()
1121import Prelude.Compat
1222
13−import Types (I, Compose3, Compose3', Approx(..))
14−import Instances ()
15−
1623import Control.Applicative (Const(..))
1724import Control.Monad (forM)
18−import Data.Aeson (FromJSONKeyFunction(..), FromJSONKey(..), decode, eitherDecode, encode, genericParseJSON, genericToJSON, genericToEncoding, object, FromJSON(..), withObject, ToJSON1(..), (.=), (.:), (.:?), (.:!))
19−import Data.Aeson.Text (encodeToTextBuilder)
25+import Data.Aeson ((.=), (.:), (.:?), (.:!), FromJSON(..), FromJSONKeyFunction(..), FromJSONKey(..), ToJSON1(..), decode, eitherDecode, encode, genericParseJSON, genericToEncoding, genericToJSON, object, withObject)
2026import Data.Aeson.Internal (JSONPathElement(..), formatError)
2127import Data.Aeson.TH (deriveJSON, deriveToJSON, deriveToJSON1)
22−import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields, Options(..), SumEncoding(..))
28+import Data.Aeson.Text (encodeToTextBuilder)
29+import Data.Aeson.Types (Options(..), SumEncoding(..), ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
2330import Data.Char (toUpper)
24−import Data.Hashable (hash)
25−import Data.List.NonEmpty (NonEmpty(..))
26−import Data.Functor.Compose (Compose (..))
31+import Data.Fixed (Pico)
32+import Data.Functor.Compose (Compose(..))
33+import Data.Functor.Identity (Identity(..))
2734import Data.Functor.Product (Product(..))
2835import Data.Functor.Sum (Sum(..))
29−import Data.Functor.Identity (Identity (..))
36+import Data.Hashable (hash)
37+import Data.List.NonEmpty (NonEmpty(..))
3038import Data.Maybe (fromMaybe)
3139import Data.Proxy (Proxy(..))
32−import Data.Fixed (Pico)
40+import Data.Scientific (Scientific)
3341import Data.Sequence (Seq)
3442import Data.Tagged (Tagged(..))
3543import Data.Text (Text)
3644import Data.Time (UTCTime)
3745import Data.Time.Format (parseTime)
3846import Data.Time.Locale.Compat (defaultTimeLocale)
47+import Data.Word (Word8)
3948import GHC.Generics (Generic)
49+import Instances ()
4050import Test.Framework (Test, testGroup)
4151import Test.Framework.Providers.HUnit (testCase)
4252import Test.HUnit (Assertion, assertFailure, assertEqual)
53+import Types (Approx(..), Compose3, Compose3', I)
4354import UnitTests.NullaryConstructors (nullaryConstructors)
44−import Data.Word (Word8)
45−import Data.Scientific (Scientific)
4655import qualified Data.ByteString.Lazy.Char8 as L
47−import qualified Data.Text.Lazy.Builder as TLB
48−import qualified Data.Text.Lazy.Encoding as TLE
49−import qualified Data.Text.Lazy as LT
50−import qualified Data.Text.Lazy.Encoding as LT
51−
5256import qualified Data.DList as DList
5357import qualified Data.HashMap.Strict as HM
5458import qualified Data.HashSet as HashSet
@@ -57,6 +61,10 @@ import qualified Data.IntSet as IntSet
5761import qualified Data.Map as M
5862import qualified Data.Sequence as Seq
5963import qualified Data.Set as Set
64+import qualified Data.Text.Lazy as LT
65+import qualified Data.Text.Lazy.Builder as TLB
66+import qualified Data.Text.Lazy.Encoding as LT
67+import qualified Data.Text.Lazy.Encoding as TLE
6068import qualified Data.Tree as Tree
6169import qualified Data.Vector as Vector
6270
tests/UnitTests/NullaryConstructors.hs+8−2
@@ -2,7 +2,13 @@
22
33{-# OPTIONS_GHC -fno-warn-deprecations #-}
44
5−module UnitTests.NullaryConstructors (nullaryConstructors) where
5+module UnitTests.NullaryConstructors
6+ (
7+ nullaryConstructors
8+ ) where
9+
10+import Prelude ()
11+import Prelude.Compat
612
713import Data.Aeson (decode, eitherDecode, fromEncoding, Value)
814import Data.Aeson.Internal (IResult (..), iparse)
@@ -10,7 +16,7 @@ import Data.Aeson.Types (Parser)
1016import Data.ByteString.Builder (toLazyByteString)
1117import Data.Maybe (fromJust)
1218import Encoders
13−import Test.HUnit (Assertion, (@=?))
19+import Test.HUnit ((@=?), Assertion)
1420import Types
1521import qualified Data.ByteString.Lazy.Char8 as L
1622