]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Model/Account.hs
Correction : LambdaCase n’est pas dans ghc-7.4 (Debian/wheezy) (bis)
[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 import Data.Text (Text)
10
11 -- import qualified Hcompta.Model.Account.Path as Path
12 import Hcompta.Lib.Regex (Regex)
13
14 -- * The 'Account' type
15
16 type Account = [Name]
17 type Name = Text -- TODO: use Text?
18
19 nil :: Account
20 nil = []
21
22 -- | Return the given 'Account' without its last 'Name' is any.
23 ascending :: Account -> Account
24 ascending [] = []
25 ascending [_] = []
26 ascending (n:a) = n:ascending a
27
28 -- | Apply the given function to all the prefixes of the given 'Account'.
29 fold :: Account -> (Account -> a -> a) -> a -> a
30 fold = loop []
31 where
32 loop :: Account -> Account -> (Account -> a -> a) -> a -> a
33 loop _path [] _f acc = acc
34 loop path (name:account) f acc =
35 let next = (Hcompta.Model.Account.++) path [name] in
36 loop next account f (f next acc)
37
38
39 -- | Return the concatenation of the given 'Account'.
40 (++) :: Account -> Account -> Account
41 (++) = (Data.List.++)
42
43 -- * The 'Joker' type
44
45 type Joker
46 = [Joker_Name]
47 data Joker_Name
48 = Joker_Any
49 | Joker_Name Name
50 deriving (Data, Eq, Read, Show, Typeable)
51
52 -- * The 'Filter' type
53
54 data Pattern
55 = Pattern_Exact Account
56 | Pattern_Joker Joker
57 | Pattern_Regex Regex
58 deriving (Read, Show, Typeable)