{-# LANGUAGE DeriveDataTypeable #-} module Hcompta.Model.Account where import Data.Data (Data) import qualified Data.List import Data.Typeable (Typeable) -- import qualified Text.Parsec as P -- import Text.Parsec (Stream, ParsecT, (<|>), ()) -- import qualified Hcompta.Model.Account.Path as Path import Hcompta.Lib.Regex (Regex) -- * The 'Account' type type Account = [Name] type Name = String nil :: Account nil = [] -- | Return the given 'Account' without its last 'Name' is any. ascending :: Account -> Account ascending [] = [] ascending [_] = [] ascending (n:a) = n:ascending a -- | Apply the given function to all the prefixes of the given 'Account'. fold :: Account -> (Account -> a -> a) -> a -> a fold = loop [] where loop :: Account -> Account -> (Account -> a -> a) -> a -> a loop _path [] _f acc = acc loop path (name:account) f acc = let next = (Hcompta.Model.Account.++) path [name] in loop next account f (f next acc) -- | Return the concatenation of the given 'Account'. (++) :: Account -> Account -> Account (++) = (Data.List.++) -- * The 'Joker' type type Joker = [Joker_Name] data Joker_Name = Joker_Any | Joker_Name Name deriving (Data, Eq, Read, Show, Typeable) -- * The 'Filter' type data Pattern = Pattern_Exact Account | Pattern_Joker Joker | Pattern_Regex Regex deriving (Read, Show, Typeable)