{-# LANGUAGE DeriveDataTypeable #-} {-# 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 Data.Semigroup (Semigroup(..)) 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 Semigroup a => Semigroup (Clusive a) where Clusive e0 i0 <> Clusive e1 i1 = Clusive (e0<>e1) (i0<>i1) instance Monoid a => Monoid (Clusive a) where mempty = Clusive mempty mempty mappend = (<>) instance NFData a => NFData (Clusive a) where rnf (Clusive e i) = rnf e `seq` rnf i