Additional of Assignment and some changes in the types.

This commit is contained in:
Ricardo H. Gracini Guiraldelli 2015-10-07 16:41:06 -07:00
parent f0c45418d4
commit 9c45025bf6
3 changed files with 31 additions and 8 deletions

12
src/Types/Assignment.hs Normal file
View file

@ -0,0 +1,12 @@
module Types.Assignment where
import qualified Data.Map as M
import qualified Types.Payer as P
import qualified Types.Bill as B
import qualified Types.Interval as I
type Assignment = M.Map B.Bill Participation
data Participation = Participation P.Payer I.Interval
assign :: P.Payer -> I.Interval -> B.Bill -> Assignment -> Assignment
assign p i b a = M.insert b (Participation p i) a

View file

@ -10,8 +10,9 @@ import qualified Data.Label as L
data Bill = Bill
{ _screenName :: T.Text
, _interval :: I.Interval
, _interval :: Maybe I.Interval
, _totalValue :: V.Value
} deriving (Eq, Ord)
L.mkLabels [''Bill]
L.mkLabels [''Bill]

View file

@ -4,22 +4,32 @@ module Types.Payer where
import qualified Data.Text as T
import qualified Data.Map.Strict as M
import qualified Types.Bill as B
import qualified Types.Bill as B (Bill)
import qualified Data.Label as L
import qualified Types.Interval as I (Interval)
import qualified Types.Value as V (Value)
data Payer = Payer
{ _screenName :: T.Text
, _bills :: M.Map B.Bill I.Interval
, _bills :: M.Map B.Bill (Proportion, I.Interval)
} deriving (Eq)
-- | 'Proportion' of 'Bill' that a 'Payer' pays.
type Proportion = Rational
L.mkLabels [''Payer]
-- | Creates a new 'Payer' with an empty list of 'Bill's.
newPayer :: T.Text -> Payer
newPayer name = Payer name M.empty
addBill' :: B.Bill -> I.Interval -> M.Map B.Bill I.Interval -> M.Map B.Bill I.Interval
addBill' b i bs = M.insert b i bs
addBill' :: B.Bill -> Proportion -> I.Interval -> M.Map B.Bill (Proportion, I.Interval) -> M.Map B.Bill (Proportion, I.Interval)
addBill' b prop i bs = M.insert b (prop, i) bs
addBill :: B.Bill -> I.Interval -> Payer -> Payer
addBill b i p = L.modify bills (addBill' b i) p
-- | Add a new 'Bill' to the 'Payer'.
addBill :: B.Bill -> Proportion -> I.Interval -> Payer -> Payer
addBill b prop i p = L.modify bills (addBill' b prop i) p
-- | Computer the cost of a particular 'Bill' for the 'Payer'.
costOf :: Payer -> B.Bill -> V.Value
costOf p b = undefined