1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 {-# LANGUAGE TypeFamilies #-}
6 module Hcompta.Posting where
8 import Control.DeepSeq (NFData)
11 -- import Data.Foldable (Foldable(..))
12 import Data.Function (($), (.))
13 import Data.Map.Strict (Map)
14 import Data.Monoid (Monoid)
16 import Data.Tuple (fst, snd)
17 import Data.Typeable ()
18 import Text.Show (Show)
19 import qualified Data.MonoTraversable as MT
21 import Hcompta.Account
29 ( Account (Posting_Account p)
30 , Amount (Posting_Amount p)
31 , MT.MonoFoldable (Posting_Amounts p)
33 type Posting_Account p
35 type Posting_Amounts p
36 posting_account :: p -> Posting_Account p
37 posting_amounts :: p -> Posting_Amounts p
39 -- Type (account, Map unit quantity)
42 , Amount (unit, quantity)
43 -- , Amount (MT.Element amounts)
44 -- , MT.MonoFoldable amounts
45 ) => Posting (account, Map unit quantity) where
46 type Posting_Account (account, Map unit quantity) = account
47 type Posting_Amount (account, Map unit quantity) = (unit, quantity) -- MT.Element amounts
48 type Posting_Amounts (account, Map unit quantity) = Map unit quantity
52 -- * Type 'Posting_Anchor'
54 newtype Posting_Anchor
55 = Posting_Anchor Anchor
56 deriving (Data, Eq, NFData, Ord, Show, Typeable)
57 newtype Posting_Anchors
58 = Posting_Anchors Anchors
59 deriving (Data, Eq, Monoid, NFData, Show, Typeable)
61 posting_anchor :: Anchor_Path -> Posting_Anchor
62 posting_anchor = Posting_Anchor . anchor
64 -- | Return the given 'Posting_Anchors' with the given 'Posting_Anchor' incorporated.
65 posting_anchor_cons :: Posting_Anchor -> Posting_Anchors -> Posting_Anchors
66 posting_anchor_cons (Posting_Anchor t) (Posting_Anchors ts) =
67 Posting_Anchors $ anchor_cons t ts
69 -- * Type 'Posting_Tag'
73 deriving (Data, Eq, NFData, Ord, Show, Typeable)
76 deriving (Data, Eq, Monoid, NFData, Show, Typeable)
78 posting_tag :: Tag_Path -> Tag_Value -> Posting_Tag
79 posting_tag p v = Posting_Tag $ tag p v
81 -- | Return the given 'Posting_Tags' with the given 'Posting_Tag' incorporated.
82 posting_tag_cons :: Posting_Tag -> Posting_Tags -> Posting_Tags
83 posting_tag_cons (Posting_Tag t) (Posting_Tags ts) =
84 Posting_Tags $ tag_cons t ts