]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Lib/Strict.hs
Commit old WIP.
[comptalang.git] / lib / Hcompta / Lib / Strict.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 module Hcompta.Lib.Strict where
4
5 import Control.DeepSeq (NFData(..))
6 import Data.Data
7 import Data.Eq (Eq)
8 import Data.Function ((.))
9 import Data.Monoid (Monoid(..))
10 import Data.NonNull (NonNull, toNullable)
11 import Data.Semigroup (Semigroup(..))
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 -- 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).
24 data Clusive a
25 = Clusive
26 { exclusive :: !a
27 , inclusive :: !a
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
34 mappend = (<>)
35 instance NFData a => NFData (Clusive a) where
36 rnf (Clusive e i) = rnf e `seq` rnf i