]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Lib/Strict.hs
Sync with symantic.
[comptalang.git] / lib / Hcompta / Lib / Strict.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE StandaloneDeriving #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module Hcompta.Lib.Strict where
5
6 import Control.DeepSeq (NFData(..))
7 import Data.Data
8 import Data.Eq (Eq)
9 import Data.Function ((.))
10 import Data.Monoid (Monoid(..))
11 import Data.NonNull (NonNull, toNullable)
12 import Prelude (seq)
13 import Text.Show (Show)
14
15 instance NFData s => NFData (NonNull s) where
16 rnf = rnf . toNullable
17
18 -- * Type 'Clusive'
19
20 -- A data type to calculate an 'inclusive' value
21 -- (through some propagation mecanism,
22 -- eg. incorporating the values of the children of a tree node),
23 -- while keeping the original 'exclusive' value
24 -- (eg. the original value of a tree node).
25 data Clusive a
26 = Clusive
27 { exclusive :: !a
28 , inclusive :: !a
29 } deriving (Data, Eq, Show, Typeable)
30 instance -- Monoid
31 Monoid a
32 => Monoid (Clusive a) where
33 mempty = Clusive mempty mempty
34 mappend (Clusive e0 i0) (Clusive e1 i1) =
35 Clusive (e0`mappend`e1) (i0`mappend`i1)
36 instance -- NFData
37 NFData a =>
38 NFData (Clusive a) where
39 rnf (Clusive e i) = rnf e `seq` rnf i