1 module Hcompta.Quantity where
4 import Data.Data (Data)
5 import Data.Eq (Eq(..))
6 import Data.Foldable (all)
7 import Data.Map.Strict (Map)
8 import qualified Data.Map.Strict as Map
9 import Data.Ord (Ord(..), Ordering(..))
10 import Prelude (Integer, Num(..))
11 import Text.Show (Show)
19 quantity_null :: a -> Bool
26 ) => Zero (Map unit q) where
27 quantity_zero = Map.empty
28 quantity_null = all quantity_null
29 instance Zero Integer where
31 quantity_null = (==) 0
33 quantity_sign :: (Zero q, Ord q) => q -> Ordering
36 _ | quantity_null q -> EQ
37 _ | q < quantity_zero -> LT
46 quantity_add :: a -> a -> a
47 instance Addable Integer where
54 ) => Addable (Map unit quantity) where
55 quantity_add = Map.unionWith quantity_add
63 quantity_neg :: a -> a
64 instance Negable Integer where
71 ) => Negable (Map unit quantity) where
72 quantity_neg = Map.map quantity_neg
80 quantity_sub :: a -> a -> a
81 instance Subable Integer where
88 ) => Subable (Map unit quantity) where
89 quantity_sub = Map.unionWith quantity_sub