1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE TypeFamilies #-}
5 {-# LANGUAGE UndecidableSuperClasses #-}
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
20 import Data.Proxy (Proxy(..))
22 import Hcompta.Account
34 _Posting :: Proxy Posting
38 class Posting (MT.Element ps) => Postings ps
39 -- type instance Gather Postings ps = Posting
40 -- type instance Gather Postings (Map acct ps) = Gather Postings ps
42 _Postings :: Proxy Postings
47 class Many Posting ps => Postings ps
49 instance Many Posting (Map acct ps) where
50 type Many_Type Posting (Map acct ps) = Many_Type Posting ps
51 instance Many Posting [p] where
52 type Many_Type Posting [p] = p
58 class Posting (Postings_Posting ps) => Postings ps where
59 type Postings_Posting ps
62 Postings (Map acct ps) where
63 type Postings_Posting (Map acct ps) = Postings_Posting ps
67 ( Account (Posting_Account p)
68 , Amounts (Posting_Amounts p)
70 type Posting_Account p
71 type Posting_Amounts p
72 posting_account :: p -> Posting_Account p
73 posting_amounts :: p -> Posting_Amounts p
74 instance -- (acct, amts)
77 ) => Posting (acct, amts) where
78 type Posting_Account (acct, amts) = acct
79 type Posting_Amounts (acct, amts) = amts
84 class Posting (Postings_Posting ps) => Postings ps where
85 type Postings_Posting ps
89 type Postings_Posting [p] = p
92 Postings (Map acct ps) where
93 type Postings_Posting (Map acct ps) = Postings_Posting ps
97 -- Type (account, Map unit quantity)
100 , Amount (unit, quantity)
101 -- , Amount (MT.Element amounts)
102 -- , MT.MonoFoldable amounts
103 ) => Posting (account, Map unit quantity) where
104 type Posting_Account (account, Map unit quantity) = account
105 type Posting_Amount (account, Map unit quantity) = (unit, quantity) -- MT.Element amounts
106 type Posting_Amounts (account, Map unit quantity) = Map unit quantity
107 posting_account = fst
108 posting_amounts = snd
110 -- * Type 'Posting_Anchor'
111 newtype Posting_Anchor
112 = Posting_Anchor Anchor
113 deriving (Data, Eq, NFData, Ord, Show, Typeable)
114 newtype Posting_Anchors
115 = Posting_Anchors Anchors
116 deriving (Data, Eq, Monoid, NFData, Show, Typeable)
118 posting_anchor :: Anchor_Path -> Posting_Anchor
119 posting_anchor = Posting_Anchor . anchor
121 -- | Return the given 'Posting_Anchors' with the given 'Posting_Anchor' incorporated.
122 posting_anchor_cons :: Posting_Anchor -> Posting_Anchors -> Posting_Anchors
123 posting_anchor_cons (Posting_Anchor t) (Posting_Anchors ts) =
124 Posting_Anchors $ anchor_cons t ts
126 -- * Type 'Posting_Tag'
129 deriving (Data, Eq, NFData, Ord, Show, Typeable)
132 deriving (Data, Eq, Monoid, NFData, Show, Typeable)
134 posting_tag :: Tag_Path -> Tag_Value -> Posting_Tag
135 posting_tag p v = Posting_Tag $ tag p v
137 -- | Return the given 'Posting_Tags' with the given 'Posting_Tag' incorporated.
138 posting_tag_cons :: Posting_Tag -> Posting_Tags -> Posting_Tags
139 posting_tag_cons (Posting_Tag t) (Posting_Tags ts) =
140 Posting_Tags $ tag_cons t ts