]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Model/Amount/Style.hs
Modif : null -> nil.
[comptalang.git] / lib / Hcompta / Model / Amount / Style.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Model.Amount.Style where
3
4 import Data.Data
5 import Data.Word (Word8)
6 import Data.Typeable ()
7
8 -- * The 'Style' type
9
10 data Style
11 = Style
12 { decimal_point :: Maybe Char
13 , format :: Maybe Format
14 , precision :: Word8
15 , unit_side :: Maybe Side
16 , unit_spaced :: Maybe Bool
17 } deriving (Data, Eq, Ord, Read, Show, Typeable)
18
19 data Side
20 = Side_Left
21 | Side_Right
22 deriving (Data, Eq, Ord, Read, Show, Typeable)
23
24 data Format
25 = Format Char [Int]
26 deriving (Data, Eq, Ord, Read, Show, Typeable)
27
28 -- * Constructors
29
30 nil :: Style
31 nil =
32 Style
33 { decimal_point = Nothing
34 , format = Nothing
35 , precision = 0
36 , unit_side = Nothing
37 , unit_spaced = Nothing
38 }
39
40 -- * Operators
41
42 union :: Style -> Style -> Style
43 union
44 style@Style
45 { decimal_point=decimal_point_
46 , format=format_
47 , precision=precision_
48 , unit_side=side
49 , unit_spaced=spaced
50 }
51 style'@Style
52 { decimal_point=decimal_point'
53 , format=format_'
54 , precision=precision'
55 , unit_side=side'
56 , unit_spaced=spaced'
57 } =
58 if style == style'
59 then style'
60 else
61 Style
62 { decimal_point=maybe decimal_point' (const decimal_point_) decimal_point_
63 , format=maybe format_' (const format_) format_
64 , precision=max precision_ precision'
65 , unit_side=maybe side' (const side) side
66 , unit_spaced=maybe spaced' (const spaced) spaced
67 }