{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-} module Hcompta.Ledger.Chart where import Control.DeepSeq (NFData(..)) import Data.Data import Data.Eq (Eq) import Data.Foldable (Foldable) import Data.Function (on, (.)) import Data.Functor (Functor) import Data.Monoid (Monoid(..)) import Data.Ord (Ord(..)) import Data.Traversable (Traversable) import Data.TreeMap.Strict (TreeMap) import Data.Typeable () import Text.Show (Show) import qualified Hcompta.Account as H import Hcompta.Ledger.Account -- * Type 'Chart' data Chart = Chart { chart_accounts :: TreeMap (H.Account_Section Account) H.Account_Tags } deriving (Data, Eq, Show, Typeable) instance NFData Chart where rnf Chart{..} = rnf chart_accounts instance Monoid Chart where mempty = Chart { chart_accounts = mempty } mappend x y = Chart { chart_accounts = chart_accounts x `mappend` chart_accounts y } -- * Type 'Charted' data Charted a = Charted { chart :: Chart , charted :: a } deriving (Data, Eq, Foldable, Functor, Show, Traversable, Typeable) instance Ord a => Ord (Charted a) where compare = compare `on` charted instance H.Account (Charted Account) where type Account_Section (Charted Account) = H.Account_Section Account account_path = H.account_path . charted