]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Amount.hs
Use symantic-document instead of walderleijen-ansi-text.
[comptalang.git] / lib / Hcompta / Amount.hs
1 module Hcompta.Amount where
2
3 import Data.Data (Data)
4 import Data.Function ((.))
5 import Data.Map.Strict (Map)
6 import qualified Data.MonoTraversable as MT
7 import Data.Ord (Ord(..), Ordering)
8 import Data.Tuple (fst, snd)
9 import Data.Proxy (Proxy(..))
10
11 import Hcompta.Quantity
12 import Hcompta.Unit (Unit(..))
13 import Hcompta.Has
14
15 class
16 ( HasI Quantity a
17 , HasI Unit a
18 ) => Amount a
19
20 class Amount (MT.Element as) => Amounts as
21
22 {-
23 -- * Class 'Amount'
24 class
25 ( Data a
26 -- , Eq (Amount_Quantity a)
27 , Zero (Amount_Quantity a)
28 , Unit (Amount_Unit a)
29 ) => Amount a where
30 type Amount_Quantity a
31 type Amount_Unit a
32 amount_quantity :: a -> Amount_Quantity a
33 amount_unit :: a -> Amount_Unit a
34 instance -- (unit, qty)
35 ( Zero qty
36 , Unit unit
37 ) => Amount (unit, qty) where
38 type Amount_Quantity (unit, qty) = qty
39 type Amount_Unit (unit, qty) = unit
40 amount_quantity = snd
41 amount_unit = fst
42 amount_sign ::
43 ( Amount a
44 , Ord (Amount_Quantity a)
45 ) => a -> Ordering
46 amount_sign = quantity_sign . amount_quantity
47
48 -- * Class 'Amounts'
49 class Amount (Amounts_Amount amts) => Amounts amts where
50 type Amounts_Amount amts
51 instance
52 ( Zero qty
53 , Unit unit
54 ) => Amounts (Map unit qty) where
55 type Amounts_Amount (Map unit qty) = (unit, qty)
56 -}