@@ -11,8 +11,8 @@ import Data.ByteString.Builder
11 (Builder, byteString, toLazyByteString, charUtf8, word8)
11 (Builder, byteString, toLazyByteString, charUtf8, word8)
13import Control.Applicative ((*>), (<$>), (<*), liftA2, pure)
13import Control.Applicative ((*>), (<$>), (<*), liftA2, pure)
14+import Control.DeepSeq (NFData(..))
14import Control.Monad (forM)
15import Control.Monad (forM)
15−import Data.Aeson.Types (Result(..), Value(..))
16import Data.Attoparsec.ByteString.Char8 (Parser, char, endOfInput, scientific,
16import Data.Attoparsec.ByteString.Char8 (Parser, char, endOfInput, scientific,
17 skipSpace, string)
17 skipSpace, string)
18import Data.Bits ((.|.), shiftL)
18import Data.Bits ((.|.), shiftL)
@@ -20,9 +20,10 @@ import Data.ByteString (ByteString)
20import Data.Char (chr)
20import Data.Char (chr)
21import Data.List (sort)
21import Data.List (sort)
22import Data.Monoid (mappend, mempty)
22import Data.Monoid (mappend, mempty)
23+import Data.Scientific (Scientific)
23import Data.Text (Text)
24import Data.Text (Text)
24import Data.Text.Encoding (decodeUtf8')
25import Data.Text.Encoding (decodeUtf8')
25−import Data.Vector as Vector (Vector, fromList)
26+import Data.Vector as Vector (Vector, foldl', fromList)
26import Data.Word (Word8)
27import Data.Word (Word8)
27import System.Directory (getDirectoryContents)
28import System.Directory (getDirectoryContents)
28import System.FilePath ((</>), dropExtension)
29import System.FilePath ((</>), dropExtension)
@@ -51,6 +52,34 @@ import Criterion.Main
51#define C_n 110
52#define C_n 110
52#define C_t 116
53#define C_t 116
55+data Result a = Error String
60+-- | A JSON \"object\" (key\/value map).
61+type Object = H.HashMap Text Value
63+-- | A JSON \"array\" (sequence).
64+type Array = Vector Value
66+-- | A JSON value represented as a Haskell value.
67+data Value = Object !Object
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
54-- | Parse a top-level JSON value. This must be either an object or
83-- | Parse a top-level JSON value. This must be either an object or
55-- an array, per RFC 4627.
84-- an array, per RFC 4627.