Revision daa79414
b/htools/Ganeti/JSON.hs | ||
---|---|---|
1 | 1 |
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-} |
2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
|
3 |
|
|
2 | 4 |
{-| JSON utility functions. -} |
3 | 5 |
|
4 | 6 |
{- |
... | ... | |
46 | 48 |
) |
47 | 49 |
where |
48 | 50 |
|
51 |
import Control.DeepSeq |
|
49 | 52 |
import Control.Monad (liftM) |
50 | 53 |
import Data.Maybe (fromMaybe, catMaybes) |
51 | 54 |
import qualified Data.Map as Map |
... | ... | |
62 | 65 |
|
63 | 66 |
-- * JSON-related functions |
64 | 67 |
|
68 |
instance NFData J.JSValue where |
|
69 |
rnf J.JSNull = () |
|
70 |
rnf (J.JSBool b) = rnf b |
|
71 |
rnf (J.JSRational b r) = rnf b `seq` rnf r |
|
72 |
rnf (J.JSString s) = rnf $ J.fromJSString s |
|
73 |
rnf (J.JSArray a) = rnf a |
|
74 |
rnf (J.JSObject o) = rnf o |
|
75 |
|
|
76 |
instance (NFData a) => NFData (J.JSObject a) where |
|
77 |
rnf = rnf . J.fromJSObject |
|
78 |
|
|
65 | 79 |
-- | A type alias for a field of a JSRecord. |
66 | 80 |
type JSField = (String, J.JSValue) |
67 | 81 |
|
... | ... | |
203 | 217 |
GenericContainer { fromContainer :: Map.Map a b } |
204 | 218 |
deriving (Show, Eq) |
205 | 219 |
|
220 |
instance (NFData a, NFData b) => NFData (GenericContainer a b) where |
|
221 |
rnf = rnf . Map.toList . fromContainer |
|
222 |
|
|
206 | 223 |
-- | Type alias for string keys. |
207 | 224 |
type Container = GenericContainer String |
208 | 225 |
|
Also available in: Unified diff