Question: Solution must be written in Haskell. 2. getMonths and monthlyCans 20% Recall that this list includes tuples where the first value in each tuple is

Solution must be written in Haskell.

Solution must be written in Haskell. 2. getMonths and monthlyCans 20% Recall

2. getMonths and monthlyCans 20% Recall that this list includes tuples where the first value in each tuple is the timestamp representing a month and the second value is the feeding log for that month. mycatsLog=[((7,2020), [(Oceanfish",7),("Tuna",1),("Whitefish",3), ("Chicken",4), ("Beef",2)]), ((8,2828), (("Oceanfish",6),("Tuna",2),("Whitefish",1),("salmon",3), ("Chicken",6)]), (9,2020), (("Tuna",3), ("Whitefish",3), ("Salmon",2), ("Chicken,5),("Beef",2), ("Turkey",1),("Sardines",1)]), ((19,2020), [("Whitefish",5),("Sardines",3), ("Chicken";7),("Beef",3)]), ((11,2820), [("Oceanfish",3), ("Tuna",2), ("Whitefish",2),("Salmon",2),("Chicken",4), ("Beef",2), ("Turkey",1)]), ((12,2020),[("Tuna",2), ("Whitefish",2), ("Salmon",2), ("Chicken",4), ("Beef",2), ("Turkey",4),("Sardines",1)]), ((1,2021),[("Chicken",7), ("Beef",3), ("Turkey",4), ("Whitefish", 1), ("Sardines",2)]) ] (a) getMonths - 10% write your getMonths function using higher-order functions (i.e., map, foldr/foldi, or filter) and without using explicit recursion. Remember that getMonths takes your cat's food log (similar to the above), a number "n", and a cat food flavor (e.g., "chicken, "Oceanfish", etc.) as input and returns the list of months whose feeding logs include more than "n" cans of the given flavor. The order of the tuples in the output can be arbitrary. The type of getMonths should be compatible with one of the following: getmonths :: (Ord ti, Eq t2) =>[(a, [(t2, t1)])) -> t1 -> t2 -> [a] getmonths :: ord ti, Eg t2) => [((a, b), [(t2, t1)])) -> ti -> tz -> [(a, b)] Hint: A possible solution uses "length" function. Examples: >getMonths myCatsLog 4 "Oceanfish" [(7,2020), (8,2020)] >getMonths myCatsLog 5 "Chicken" [(8,2020), (10,2020), (1, 2021)] (b) monthlyCans - 10% Define a function monthlycans, which calculates the number of cans you fed to your cat each month. It takes your cat's food log (similar to the above) as input and returns a list of tuples where the first element in each tuple is the timestamp (i.e., (month, year)), and the second value is the total number of cans your cat consumed during that month. Your function shouldn't need a recursion but should use a higher order function (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. The order of the tuples in the output can be arbitrary. The type of the function should be compatible with one of the following: monthlycans :: Num t1 => [(a, [(t2, t1)])] -> [(a, t1)] monthlycans :: Num t1 => [((a1, a2), [(t2, t1)]] -> [((a1, a2), t1)] Examples: > monthlyCans myCatsLog [((7, 2020),17), (18,2020), 18), ((9,2020), 17), ((10,2020), 18), ((11,2020),16), ((12 ,2020), 17), ((1,2021), 17)] 2. getMonths and monthlyCans 20% Recall that this list includes tuples where the first value in each tuple is the timestamp representing a month and the second value is the feeding log for that month. mycatsLog=[((7,2020), [(Oceanfish",7),("Tuna",1),("Whitefish",3), ("Chicken",4), ("Beef",2)]), ((8,2828), (("Oceanfish",6),("Tuna",2),("Whitefish",1),("salmon",3), ("Chicken",6)]), (9,2020), (("Tuna",3), ("Whitefish",3), ("Salmon",2), ("Chicken,5),("Beef",2), ("Turkey",1),("Sardines",1)]), ((19,2020), [("Whitefish",5),("Sardines",3), ("Chicken";7),("Beef",3)]), ((11,2820), [("Oceanfish",3), ("Tuna",2), ("Whitefish",2),("Salmon",2),("Chicken",4), ("Beef",2), ("Turkey",1)]), ((12,2020),[("Tuna",2), ("Whitefish",2), ("Salmon",2), ("Chicken",4), ("Beef",2), ("Turkey",4),("Sardines",1)]), ((1,2021),[("Chicken",7), ("Beef",3), ("Turkey",4), ("Whitefish", 1), ("Sardines",2)]) ] (a) getMonths - 10% write your getMonths function using higher-order functions (i.e., map, foldr/foldi, or filter) and without using explicit recursion. Remember that getMonths takes your cat's food log (similar to the above), a number "n", and a cat food flavor (e.g., "chicken, "Oceanfish", etc.) as input and returns the list of months whose feeding logs include more than "n" cans of the given flavor. The order of the tuples in the output can be arbitrary. The type of getMonths should be compatible with one of the following: getmonths :: (Ord ti, Eq t2) =>[(a, [(t2, t1)])) -> t1 -> t2 -> [a] getmonths :: ord ti, Eg t2) => [((a, b), [(t2, t1)])) -> ti -> tz -> [(a, b)] Hint: A possible solution uses "length" function. Examples: >getMonths myCatsLog 4 "Oceanfish" [(7,2020), (8,2020)] >getMonths myCatsLog 5 "Chicken" [(8,2020), (10,2020), (1, 2021)] (b) monthlyCans - 10% Define a function monthlycans, which calculates the number of cans you fed to your cat each month. It takes your cat's food log (similar to the above) as input and returns a list of tuples where the first element in each tuple is the timestamp (i.e., (month, year)), and the second value is the total number of cans your cat consumed during that month. Your function shouldn't need a recursion but should use a higher order function (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. The order of the tuples in the output can be arbitrary. The type of the function should be compatible with one of the following: monthlycans :: Num t1 => [(a, [(t2, t1)])] -> [(a, t1)] monthlycans :: Num t1 => [((a1, a2), [(t2, t1)]] -> [((a1, a2), t1)] Examples: > monthlyCans myCatsLog [((7, 2020),17), (18,2020), 18), ((9,2020), 17), ((10,2020), 18), ((11,2020),16), ((12 ,2020), 17), ((1,2021), 17)]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!