@@ -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--