git.iko.soy/typeable/attoparsec
on master help sign in
Drop direct dependency on aeson

--HG-- extra : rebase_source : 6560f9f563fd2077685f14218f95243508e88685

commita3e555edf1d538a62e61fb4f41360fea7b0da937 authorBryan O'Sullivan <bos@serpentine.com> dateWed 14 May 2014, 18:11 (12 years ago) parent9ad54b1
2 files changed+31−3
benchmarks/Aeson.hs+31−2 benchmarks/attoparsec-benchmarks.cabal−1
benchmarks/Aeson.hs+31−2
@@ -11,8 +11,8 @@ import Data.ByteString.Builder
1111 (Builder, byteString, toLazyByteString, charUtf8, word8)
1212
1313import Control.Applicative ((*>), (<$>), (<*), liftA2, pure)
14+import Control.DeepSeq (NFData(..))
1415import Control.Monad (forM)
15−import Data.Aeson.Types (Result(..), Value(..))
1616import Data.Attoparsec.ByteString.Char8 (Parser, char, endOfInput, scientific,
1717 skipSpace, string)
1818import Data.Bits ((.|.), shiftL)
@@ -20,9 +20,10 @@ import Data.ByteString (ByteString)
2020import Data.Char (chr)
2121import Data.List (sort)
2222import Data.Monoid (mappend, mempty)
23+import Data.Scientific (Scientific)
2324import Data.Text (Text)
2425import Data.Text.Encoding (decodeUtf8')
25−import Data.Vector as Vector (Vector, fromList)
26+import Data.Vector as Vector (Vector, foldl', fromList)
2627import Data.Word (Word8)
2728import System.Directory (getDirectoryContents)
2829import System.FilePath ((</>), dropExtension)
@@ -51,6 +52,34 @@ import Criterion.Main
5152#define C_n 110
5253#define C_t 116
5354
55+data Result a = Error String
56+ | Success a
57+ deriving (Eq, Show)
58+
59+
60+-- | A JSON \"object\" (key\/value map).
61+type Object = H.HashMap Text Value
62+
63+-- | A JSON \"array\" (sequence).
64+type Array = Vector Value
65+
66+-- | A JSON value represented as a Haskell value.
67+data Value = Object !Object
68+ | Array !Array
69+ | String !Text
70+ | Number !Scientific
71+ | Bool !Bool
72+ | Null
73+ deriving (Eq, Show)
74+
75+instance NFData Value where
76+ rnf (Object o) = rnf o
77+ rnf (Array a) = Vector.foldl' (\x y -> rnf y `seq` x) () a
78+ rnf (String s) = rnf s
79+ rnf (Number n) = rnf n
80+ rnf (Bool b) = rnf b
81+ rnf Null = ()
82+
5483-- | Parse a top-level JSON value. This must be either an object or
5584-- an array, per RFC 4627.
5685--
benchmarks/attoparsec-benchmarks.cabal−1
@@ -16,7 +16,6 @@ executable attoparsec-benchmarks
1616 hs-source-dirs: .. .
1717 ghc-options: -O2 -Wall
1818 build-depends:
19− aeson,
2019 array,
2120 base == 4.*,
2221 bytestring >= 0.10.4.0,