]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Amount.hs
Adapte hcompta-cli.
[comptalang.git] / lib / Hcompta / Amount.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE TypeFamilies #-}
4 module Hcompta.Amount where
5
6 import Data.Data (Data)
7 import Data.Eq (Eq(..))
8 import Data.Function ((.))
9 import Data.Ord (Ord(..), Ordering)
10 import Data.Tuple (fst, snd)
11
12 import Hcompta.Quantity
13 import Hcompta.Unit (Unit(..))
14
15 -- * Class 'Amount'
16
17 class
18 ( Data a
19 , Eq (Amount_Quantity a)
20 , Zero (Amount_Quantity a)
21 , Unit (Amount_Unit a)
22 ) => Amount a where
23 type Amount_Quantity a
24 type Amount_Unit a
25 amount_quantity :: a -> Amount_Quantity a
26 amount_unit :: a -> Amount_Unit a
27 instance -- Type (unit, quantity)
28 ( Zero quantity
29 , Eq quantity
30 , Unit unit
31 ) => Amount (unit, quantity) where
32 type Amount_Quantity (unit, quantity) = quantity
33 type Amount_Unit (unit, quantity) = unit
34 amount_quantity = snd
35 amount_unit = fst
36
37 amount_sign
38 :: ( Amount a
39 , Ord (Amount_Quantity a)
40 )
41 => a -> Ordering
42 amount_sign = quantity_sign . amount_quantity