1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 module Hcompta.Lib.Strict where
5 import Control.DeepSeq (NFData(..))
8 import Data.Function ((.))
9 import Data.Monoid (Monoid(..))
10 import Data.NonNull (NonNull, toNullable)
11 import Data.Semigroup (Semigroup(..))
13 import Text.Show (Show)
15 instance NFData s => NFData (NonNull s) where
16 rnf = rnf . toNullable
19 -- A data type to calculate an 'inclusive' value
20 -- (through some propagation mecanism,
21 -- eg. incorporating the values of the children of a tree node),
22 -- while keeping the original 'exclusive' value
23 -- (eg. the original value of a tree node).
28 } deriving (Data, Eq, Show, Typeable)
29 instance Semigroup a => Semigroup (Clusive a) where
30 Clusive e0 i0 <> Clusive e1 i1 =
31 Clusive (e0<>e1) (i0<>i1)
32 instance Monoid a => Monoid (Clusive a) where
33 mempty = Clusive mempty mempty
35 instance NFData a => NFData (Clusive a) where
36 rnf (Clusive e i) = rnf e `seq` rnf i