Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 6 --
  2. itemTotal :: [(String, Float)] -> [(String, Float)]
  3. itemTotal [] = []
  4.  
  5. itemTotal (x:xs)
  6.    | elementInList (fst x) xs == True = itemTotal (sumPrices xs (fst x) (snd x))
  7.    | otherwise = x:(itemTotal xs)
  8.    
  9.    
  10. elementInList :: String -> [(String, Float)] -> Bool
  11. elementInList _ [] = False
  12. elementInList y (x:xs)
  13.    | y == fst x = True
  14.    | otherwise = elementInList y xs
  15.    
  16.    
  17. sumPrices :: [(String, Float)] -> String -> Float -> [(String, Float)]
  18. sumPrices [] _ _ = []
  19. sumPrices (x:xs) y price
  20.   | fst x == y = (y, snd x + price):xs
  21.   | otherwise = x:(sumPrices xs y price)
  22.  
  23. ---------------
  24.  
  25. itemDiscount :: String -> Float -> [(String, Float)] -> [(String, Float)]
  26. itemDiscount _ _ [] = []
  27. itemDiscount item discount (x:xs)
  28.   | item == fst x = (item, applyDiscount (snd x) discount):(itemDiscount item discount xs)
  29.   | otherwise = x:(itemDiscount item discount xs)
  30.  
  31.  
  32. applyDiscount :: Float -> Float -> Float
  33. applyDiscount price discount = price * ((100-discount) / 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement