diff --git a/htools/Ganeti/JSON.hs b/htools/Ganeti/JSON.hs index 30b80d8292098e24ff905ed400f583654d5325d0..dc8dc0fe824b5a52b808c98fe9a403359fade339 100644 --- a/htools/Ganeti/JSON.hs +++ b/htools/Ganeti/JSON.hs @@ -1,4 +1,6 @@ {-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + {-| JSON utility functions. -} {- @@ -46,6 +48,7 @@ module Ganeti.JSON ) where +import Control.DeepSeq import Control.Monad (liftM) import Data.Maybe (fromMaybe, catMaybes) import qualified Data.Map as Map @@ -62,6 +65,17 @@ import Ganeti.BasicTypes -- * JSON-related functions +instance NFData J.JSValue where + rnf J.JSNull = () + rnf (J.JSBool b) = rnf b + rnf (J.JSRational b r) = rnf b `seq` rnf r + rnf (J.JSString s) = rnf $ J.fromJSString s + rnf (J.JSArray a) = rnf a + rnf (J.JSObject o) = rnf o + +instance (NFData a) => NFData (J.JSObject a) where + rnf = rnf . J.fromJSObject + -- | A type alias for a field of a JSRecord. type JSField = (String, J.JSValue) @@ -203,6 +217,9 @@ newtype GenericContainer a b = GenericContainer { fromContainer :: Map.Map a b } deriving (Show, Eq) +instance (NFData a, NFData b) => NFData (GenericContainer a b) where + rnf = rnf . Map.toList . fromContainer + -- | Type alias for string keys. type Container = GenericContainer String