Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 6 --
- itemTotal :: [(String, Float)] -> [(String, Float)]
- itemTotal [] = []
- itemTotal (x:xs)
- | elementInList (fst x) xs == True = itemTotal (sumPrices xs (fst x) (snd x))
- | otherwise = x:(itemTotal xs)
- elementInList :: String -> [(String, Float)] -> Bool
- elementInList _ [] = False
- elementInList y (x:xs)
- | y == fst x = True
- | otherwise = elementInList y xs
- sumPrices :: [(String, Float)] -> String -> Float -> [(String, Float)]
- sumPrices [] _ _ = []
- sumPrices (x:xs) y price
- | fst x == y = (y, snd x + price):xs
- | otherwise = x:(sumPrices xs y price)
- ---------------
- itemDiscount :: String -> Float -> [(String, Float)] -> [(String, Float)]
- itemDiscount _ _ [] = []
- itemDiscount item discount (x:xs)
- | item == fst x = (item, applyDiscount (snd x) discount):(itemDiscount item discount xs)
- | otherwise = x:(itemDiscount item discount xs)
- applyDiscount :: Float -> Float -> Float
- applyDiscount price discount = price * ((100-discount) / 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement