1{-# LANGUAGE DeriveDataTypeable, DeriveGeneric, TemplateHaskell #-}
5--------------------------------------------------------------------------------
9import Control.DeepSeq (NFData, rnf, deepseq)
11import Data.Typeable (Typeable)
12import Data.Data (Data)
13import GHC.Generics (Generic)
15import Data.Aeson.Types
16import Data.Aeson.TH (mkToJSON, mkParseJSON)
17import qualified Data.Aeson.Generic as G (fromJSON, toJSON)
19--------------------------------------------------------------------------------
21-- Taken from the documentation of Data.Aeson.TH:
24 | Product String Char a
25 | Record { testOne :: Double
28 } deriving (Show, Eq, Generic, Data, Typeable)
30instance NFData a => NFData (D a) where
33 rnf (Product s c x) = s `deepseq` c `deepseq` rnf x
34 rnf (Record d b y) = d `deepseq` b `deepseq` rnf y
40 { testOne = 1234.56789
42 , testThree = Product "Hello World!" 'a' $
44 { testOne = 9876.54321
46 , testThree = Product "Yeehaa!!!" '\n' Nullary
50instance ToJSON a => ToJSON (D a)
51instance FromJSON a => FromJSON (D a)
53thDToJSON :: ToJSON a => D a -> Value
54thDToJSON = $(mkToJSON id ''D)
56thDParseJSON :: FromJSON a => Value -> Parser (D a)
57thDParseJSON = $(mkParseJSON id ''D)
59thDFromJSON :: FromJSON a => Value -> Result (D a)
60thDFromJSON = parse thDParseJSON
62--------------------------------------------------------------------------------
64data BigRecord = BigRecord
65 { field01 :: !Int, field02 :: !Int, field03 :: !Int, field04 :: !Int, field05 :: !Int
66 , field06 :: !Int, field07 :: !Int, field08 :: !Int, field09 :: !Int, field10 :: !Int
67 , field11 :: !Int, field12 :: !Int, field13 :: !Int, field14 :: !Int, field15 :: !Int
68 , field16 :: !Int, field17 :: !Int, field18 :: !Int, field19 :: !Int, field20 :: !Int
69 , field21 :: !Int, field22 :: !Int, field23 :: !Int, field24 :: !Int, field25 :: !Int
70 } deriving (Show, Eq, Generic, Data, Typeable)
72instance NFData BigRecord
74bigRecord = BigRecord 1 2 3 4 5
80instance ToJSON BigRecord
81instance FromJSON BigRecord
83thBigRecordToJSON :: BigRecord -> Value
84thBigRecordToJSON = $(mkToJSON id ''BigRecord)
86thBigRecordParseJSON :: Value -> Parser BigRecord
87thBigRecordParseJSON = $(mkParseJSON id ''BigRecord)
89thBigRecordFromJSON :: Value -> Result BigRecord
90thBigRecordFromJSON = parse thBigRecordParseJSON
92--------------------------------------------------------------------------------
94data BigProduct = BigProduct
95 !Int !Int !Int !Int !Int
96 !Int !Int !Int !Int !Int
97 !Int !Int !Int !Int !Int
98 !Int !Int !Int !Int !Int
99 !Int !Int !Int !Int !Int
100 deriving (Show, Eq, Generic, Data, Typeable)
102instance NFData BigProduct
104bigProduct = BigProduct 1 2 3 4 5
110instance ToJSON BigProduct
111instance FromJSON BigProduct
113thBigProductToJSON :: BigProduct -> Value
114thBigProductToJSON = $(mkToJSON id ''BigProduct)
116thBigProductParseJSON :: Value -> Parser BigProduct
117thBigProductParseJSON = $(mkParseJSON id ''BigProduct)
119thBigProductFromJSON :: Value -> Result BigProduct
120thBigProductFromJSON = parse thBigProductParseJSON
122--------------------------------------------------------------------------------
124data BigSum = F01 | F02 | F03 | F04 | F05
125 | F06 | F07 | F08 | F09 | F10
126 | F11 | F12 | F13 | F14 | F15
127 | F16 | F17 | F18 | F19 | F20
128 | F21 | F22 | F23 | F24 | F25
129 deriving (Show, Eq, Generic, Data, Typeable)
131instance NFData BigSum
135instance ToJSON BigSum
136instance FromJSON BigSum
138thBigSumToJSON :: BigSum -> Value
139thBigSumToJSON = $(mkToJSON id ''BigSum)
141thBigSumParseJSON :: Value -> Parser BigSum
142thBigSumParseJSON = $(mkParseJSON id ''BigSum)
144thBigSumFromJSON :: Value -> Result BigSum
145thBigSumFromJSON = parse thBigSumParseJSON
147--------------------------------------------------------------------------------
149type FJ a = Value -> Result a
153 [ let v = thDToJSON d
154 in d `deepseq` v `deepseq`
156 [ group "toJSON" (nf thDToJSON d)
159 , group "fromJSON" (nf (thDFromJSON :: FJ T) v)
160 (nf (G.fromJSON :: FJ T) v)
161 (nf (fromJSON :: FJ T) v)
163 , let v = thBigRecordToJSON bigRecord
164 in bigRecord `deepseq` v `deepseq`
166 [ group "toJSON" (nf thBigRecordToJSON bigRecord)
167 (nf G.toJSON bigRecord)
168 (nf toJSON bigRecord)
169 , group "fromJSON" (nf (thBigRecordFromJSON :: FJ BigRecord) v)
170 (nf (G.fromJSON :: FJ BigRecord) v)
171 (nf (fromJSON :: FJ BigRecord) v)
173 , let v = thBigProductToJSON bigProduct
174 in bigProduct `deepseq` v `deepseq`
176 [ group "toJSON" (nf thBigProductToJSON bigProduct)
177 (nf G.toJSON bigProduct)
178 (nf toJSON bigProduct)
179 , group "fromJSON" (nf (thBigProductFromJSON :: FJ BigProduct) v)
180 (nf (G.fromJSON :: FJ BigProduct) v)
181 (nf (fromJSON :: FJ BigProduct) v)
183 , let v = thBigSumToJSON bigSum
184 in bigSum `deepseq` v `deepseq`
186 [ group "toJSON" (nf thBigSumToJSON bigSum)
189 , group "fromJSON" (nf (thBigSumFromJSON :: FJ BigSum) v)
190 (nf (G.fromJSON :: FJ BigSum) v)
191 (nf (fromJSON :: FJ BigSum) v)
195group n th syb gen = bgroup n [ bench "th" th
197 , bench "generic" gen
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list