{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -fno-warn-deprecations #-} -- FIXME: to be removed when dropping GHC-7.6 support {-# OPTIONS_GHC -fno-warn-orphans #-} module Hcompta.Lib.Strict where import Control.DeepSeq (NFData(..)) import Data.Data import Data.Eq (Eq) import Data.Monoid (Monoid(..)) import qualified Data.Strict.Maybe as Strict import Text.Show (Show) -- 'Strict.Maybe' orphans instances deriving instance -- Data Data x => Data (Strict.Maybe x) instance -- Monoid Monoid x => Monoid (Strict.Maybe x) where mempty = Strict.Nothing mappend (Strict.Just x) (Strict.Just y) = Strict.Just (x `mappend` y) mappend x Strict.Nothing = x mappend Strict.Nothing y = y instance -- NFData NFData x => NFData (Strict.Maybe x) where rnf Strict.Nothing = () rnf (Strict.Just x) = rnf x deriving instance -- Typeable Typeable1 Strict.Maybe -- Type 'Clusive' -- A data type to calculate an 'inclusive' value -- (through some propagation mecanism, -- eg. incorporating the values of the children of a tree node), -- while keeping the original 'exclusive' value -- (eg. the original value of a tree node). data Clusive a = Clusive { exclusive :: !a , inclusive :: !a } deriving (Data, Eq, Show, Typeable) instance -- Monoid Monoid a => Monoid (Clusive a) where mempty = Clusive mempty mempty mappend (Clusive e0 i0) (Clusive e1 i1) = Clusive (e0`mappend`e1) (i0`mappend`i1)