]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Model/Account.hs
Ajout : Calc.Balance types and constructors.
[comptalang.git] / lib / Hcompta / Model / Account.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Model.Account where
3
4 import Data.Data
5 import Data.Function (on)
6 import qualified Data.List
7 import qualified Data.Map
8 import Data.Map (Map)
9 import Data.Maybe (fromMaybe)
10 import Data.Typeable ()
11
12 -- import qualified Hcompta.Model.Account.Path as Path
13 import qualified Hcompta.Model.Amount as Amount
14 import Hcompta.Model.Amount (Amount)
15 import qualified Hcompta.Model.Transaction.Tag as Tag
16 import Hcompta.Model.Transaction.Tag (Tag)
17
18 -- * The 'Account' type
19
20 type Account = [Name]
21 type Name = String
22
23 null :: Account
24 null = []
25
26 -- | Apply the given function to all the prefixes of the given 'Account'.
27 fold :: Account -> (Account -> a -> a) -> a -> a
28 fold = loop []
29 where
30 loop :: Account -> Account -> (Account -> a -> a) -> a -> a
31 loop _path [] _f acc = acc
32 loop path (name:account) f acc =
33 let next = path++[name] in
34 loop next account f (f next acc)
35
36
37 -- | Return the given 'Account' without its last 'Name'.
38 chomp :: Account -> Account
39 chomp [] = []
40 chomp [a] = []
41 chomp (n:a) = n:chomp a