{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeFamilies #-} module Hcompta.Amount where import Data.Data (Data) import Data.Function ((.)) import Data.Map.Strict (Map) import qualified Data.MonoTraversable as MT import Data.Ord (Ord(..), Ordering) import Data.Tuple (fst, snd) import Data.Proxy (Proxy(..)) import Hcompta.Quantity import Hcompta.Unit (Unit(..)) import Hcompta.Has class ( HasI Quantity a , HasI Unit a ) => Amount a _Amount :: Proxy Amount _Amount = Proxy class Amount (MT.Element as) => Amounts as _Amounts :: Proxy Amounts _Amounts = Proxy {- -- * Class 'Amount' class ( Data a -- , Eq (Amount_Quantity a) , Zero (Amount_Quantity a) , Unit (Amount_Unit a) ) => Amount a where type Amount_Quantity a type Amount_Unit a amount_quantity :: a -> Amount_Quantity a amount_unit :: a -> Amount_Unit a instance -- (unit, qty) ( Zero qty , Unit unit ) => Amount (unit, qty) where type Amount_Quantity (unit, qty) = qty type Amount_Unit (unit, qty) = unit amount_quantity = snd amount_unit = fst amount_sign :: ( Amount a , Ord (Amount_Quantity a) ) => a -> Ordering amount_sign = quantity_sign . amount_quantity -- * Class 'Amounts' class Amount (Amounts_Amount amts) => Amounts amts where type Amounts_Amount amts instance ( Zero qty , Unit unit ) => Amounts (Map unit qty) where type Amounts_Amount (Map unit qty) = (unit, qty) -}