The Task

You are to write a number of functions that perform queries for an inventory system.
Type definitions
We will be dealing with customers and products, described by the type synonyms
type Customer = String
type Product = String
An order of some quantity of a product by a customer is described by the type
data Order = Order Customer Product Double
deriving (Show)

You may assume that the quantity is greater than zero. Lists of orders may contain multiple orders by the same customer of the same product (not necessarily adjacent to each other). A delivery to the supplier of some quantity of a product is described by the type data Delivery = Delivery Product Double
deriving (Show)
Again you may assume that the quantity is greater than zero. Lists of deliveries may include multiple deliveries of the same product (not necessarily adjacent to each other).

Functions to be written
You are asked to implement five functions operating on these types. They are assigned equal marks, but you will find that later ones are more difficult than earlier ones.
majority :: [Order] > [(Customer, Product)]
the list of customers and products for which the customer has ordered more than half the total quantity for that product.
share :: [Order] > [Delivery] > [(Customer, Product, Double)]
an allocation of quantities of products to customers. No customer should be allocated more of a given product than they have ordered. If a sufficient quantity of a product has been delivered to satisfy all orders, each customer should receive the total quantity they ordered. If not, the
available quantity of the product should be shared between customers in proportion to the amount ordered. For example, if the delivered quantity of a product is half the the total ordered quantity of that product, each customer would receive half of what they ordered.
For each part, you should add a brief comment explaining the strategy you have used, not a translation of the code into English.
There are many different ways of implementing these functions, so I am not expecting to see identical or strongly similar answer.


    Customer Area

    Make your order right away

    Confidentiality and privacy guaranteed

    satisfaction guaranteed