]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Model/Account.hs
Correction : warnings.
[comptalang.git] / lib / Hcompta / Model / Account.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Model.Account where
3
4 import Data.Data (Data)
5 import qualified Data.List
6 import Data.Typeable (Typeable)
7 -- import qualified Text.Parsec as P
8 -- import Text.Parsec (Stream, ParsecT, (<|>), (<?>))
9
10 -- import qualified Hcompta.Model.Account.Path as Path
11 import Hcompta.Lib.Regex (Regex)
12
13 -- * The 'Account' type
14
15 type Account = [Name]
16 type Name = String
17
18 nil :: Account
19 nil = []
20
21 -- | Return the given 'Account' without its last 'Name' is any.
22 ascending :: Account -> Account
23 ascending [] = []
24 ascending [_] = []
25 ascending (n:a) = n:ascending a
26
27 -- | Apply the given function to all the prefixes of the given 'Account'.
28 fold :: Account -> (Account -> a -> a) -> a -> a
29 fold = loop []
30 where
31 loop :: Account -> Account -> (Account -> a -> a) -> a -> a
32 loop _path [] _f acc = acc
33 loop path (name:account) f acc =
34 let next = (Hcompta.Model.Account.++) path [name] in
35 loop next account f (f next acc)
36
37
38 -- | Return the concatenation of the given 'Account'.
39 (++) :: Account -> Account -> Account
40 (++) = (Data.List.++)
41
42 -- * The 'Joker' type
43
44 type Joker
45 = [Joker_Name]
46 data Joker_Name
47 = Joker_Any
48 | Joker_Name Name
49 deriving (Data, Eq, Read, Show, Typeable)
50
51 -- * The 'Filter' type
52
53 data Pattern
54 = Pattern_Exact Account
55 | Pattern_Joker Joker
56 | Pattern_Regex Regex
57 deriving (Read, Show, Typeable)