{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Hcompta.Lib.Strict where import Control.DeepSeq (NFData(..)) import Data.Data import Data.Eq (Eq) import Data.Function ((.)) import Data.Monoid (Monoid(..)) import Data.NonNull (NonNull, toNullable) import Prelude (seq) import Text.Show (Show) instance NFData s => NFData (NonNull s) where rnf = rnf . toNullable -- * 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) instance -- NFData NFData a => NFData (Clusive a) where rnf (Clusive e i) = rnf e `seq` rnf i