1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE TypeFamilies #-}
4 module Hcompta.Amount where
6 import Data.Data (Data)
7 import Data.Function ((.))
8 import Data.Map.Strict (Map)
9 import qualified Data.MonoTraversable as MT
10 import Data.Ord (Ord(..), Ordering)
11 import Data.Tuple (fst, snd)
12 import Data.Proxy (Proxy(..))
14 import Hcompta.Quantity
15 import Hcompta.Unit (Unit(..))
23 _Amount :: Proxy Amount
26 class Amount (MT.Element as) => Amounts as
28 _Amounts :: Proxy Amounts
35 -- , Eq (Amount_Quantity a)
36 , Zero (Amount_Quantity a)
37 , Unit (Amount_Unit a)
39 type Amount_Quantity a
41 amount_quantity :: a -> Amount_Quantity a
42 amount_unit :: a -> Amount_Unit a
43 instance -- (unit, qty)
46 ) => Amount (unit, qty) where
47 type Amount_Quantity (unit, qty) = qty
48 type Amount_Unit (unit, qty) = unit
53 , Ord (Amount_Quantity a)
55 amount_sign = quantity_sign . amount_quantity
58 class Amount (Amounts_Amount amts) => Amounts amts where
59 type Amounts_Amount amts
63 ) => Amounts (Map unit qty) where
64 type Amounts_Amount (Map unit qty) = (unit, qty)