(a) elemAll 10% Write a Haskell function elemAll that takes two lists as input and returns...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(a) elemAll 10% Write a Haskell function elemAll that takes two lists as input and returns True if all elements in the first list appear in the second list. It returns False otherwise. Note that both input lists should have the same type. Your function shouldn't need a recursion but should use higher order functions (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. Note: You can use the built-in "elem" function in your solution. Examples: > elemAll [3,5,7,10] [1,2,3,4,5,6,7,8,9,10] True > elemAll [3,5,10] [1,2,3,4,5,6,7,8,9] False > elemAll ["Bishop", "TerreView","Walmart"] ["Chinook", "Orchard","Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight" , "Campus"] True > elemAll ["Bishop", "TerreView"] ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"] False (b) stopsAt 10% Pullman Transit offers many bus routes in Pullman. Assume we store the bus stops for the bus routes in a list of tuples. The first element of each tuple is the bus route and the second element is the list of stops for that route (see below for an example). buses = [("Wheat", ["Chinook", "Orchard", "Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight", "Campus"]), ("Silver", ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"]), ("Blue", ["TransferStation", "State", "Larry", "TerreView","Grand", "TacoBell", "Chinook", "Library"]), ("Gray", ["TransferStation", "Wawawai", "Main", "Sunnyside", "Crestview", "CityHall", "Stadium", "Colorado"]) ] Write a Haskell function stopsat, that takes a list of bus stop names 'stops' and the bus route data 'buses' (similar to the above) as input and returns the bus route names that stop at each and every stop in 'stops'. Your function shouldn't need a recursion but should use higher order functions (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 route names in the output can be arbitrary. Hint: You can use the "elemAll" function you defined in part(a) in your solution. Examples: > stopsAt ["Bishop", "TerreView", "Walmart"] buses ["Wheat"] >stopsAt ["Bishop", "Walmart"] buses ["Wheat", "Silver"] >p2b_test3 = stopsAt ["Transfer Station", "State", "Main"] buses [ ] (a) elemAll 10% Write a Haskell function elemAll that takes two lists as input and returns True if all elements in the first list appear in the second list. It returns False otherwise. Note that both input lists should have the same type. Your function shouldn't need a recursion but should use higher order functions (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. Note: You can use the built-in "elem" function in your solution. Examples: > elemAll [3,5,7,10] [1,2,3,4,5,6,7,8,9,10] True > elemAll [3,5,10] [1,2,3,4,5,6,7,8,9] False > elemAll ["Bishop", "TerreView","Walmart"] ["Chinook", "Orchard","Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight" , "Campus"] True > elemAll ["Bishop", "TerreView"] ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"] False (b) stopsAt 10% Pullman Transit offers many bus routes in Pullman. Assume we store the bus stops for the bus routes in a list of tuples. The first element of each tuple is the bus route and the second element is the list of stops for that route (see below for an example). buses = [("Wheat", ["Chinook", "Orchard", "Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight", "Campus"]), ("Silver", ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"]), ("Blue", ["TransferStation", "State", "Larry", "TerreView","Grand", "TacoBell", "Chinook", "Library"]), ("Gray", ["TransferStation", "Wawawai", "Main", "Sunnyside", "Crestview", "CityHall", "Stadium", "Colorado"]) ] Write a Haskell function stopsat, that takes a list of bus stop names 'stops' and the bus route data 'buses' (similar to the above) as input and returns the bus route names that stop at each and every stop in 'stops'. Your function shouldn't need a recursion but should use higher order functions (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 route names in the output can be arbitrary. Hint: You can use the "elemAll" function you defined in part(a) in your solution. Examples: > stopsAt ["Bishop", "TerreView", "Walmart"] buses ["Wheat"] >stopsAt ["Bishop", "Walmart"] buses ["Wheat", "Silver"] >p2b_test3 = stopsAt ["Transfer Station", "State", "Main"] buses [ ]
Expert Answer:
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
write the answer on Haskell Notation The US currency is the dollar. 1 dollar = 100 cents. In US currency, there are several types of coins, each of which is given a name, namely quarter (1 quarter =...
-
Haskell Corporation reported the following operating results for two consecutive years. _______________________2019 2018 Percentage Change Sales ........................$550,000.....................
-
Please Identify relevant ethical issues presented by consulting AICPA Code of Professional Conduct. In your memo response, please site specific sections from the Code of Conduct that you used to...
-
Ned and Nelly Norbert, both aged 35, have three small children. Nancy aged 10, Nadia aged 8, and Nadine aged 3. The Norberts want to ensure that they have adequate resources in place to complete...
-
Multiple Choice Questions Select the best answer for each of the following and explain fully the reason for your selection. a. A report on an attestation engagement should: (1) State the nature of...
-
Grain growth is strongly dependent on temperature (i.e., rate of grain growth increases with increasing temperature), yet temperature is not explicitly given as a part of Equation 7.9. (a) Into which...
-
Thermal regeneration of a fixed-bed adsorber is based on the fact that the adsorption process is exothermic; therefore, heating the saturated adsorbent will result in desorption. The dynamics of the...
-
Long-term Liability Transactions. Following are a number of unrelated transactions for K-Town, some of which affect governmental activities at the government-wide level. None of the transactions has...
-
Defend the following statement: Data and database administration are even more important in the decentralized IS environment than in the centralized one
-
Get It Right, CPAs, has been retained to review its client's corporate formation calculations for 20XX. Maria, Roger, and Novak created Grassroots Tennis, Inc. (GTI), which began operations on March...
-
A production function for dental services would include dentist hours, dental hygienist hours, dental assistant hours, receptionist hours, medical supplies, energy use, medical equipment, and the...
-
October OB Data: Admissions: Discharges: 555 65 61 Deaths: 1 Number delivered by C-section Undelivered: Delivered Live Single infant Total 50 15 Twins 3 sets 1 set Triplets 1 set 0 Dead Stillborn 1 1...
-
If Florence Nightingale were alive today and took the position that nurses represent Plato's guardian class and doctors represent the artisan class, would she be correct? Why or why not ? Explain
-
The manager of the coffee shop hired two employees from the training company to help with communication problems in his shop general. 1. Customer 1 comes inside the shop and looks around the menu 2....
-
Museum A: Museum A has been around for 500 years and is located in a major world city. It displays art and artifacts from all over the world. It is considered one of the most comprehensive museums in...
-
What hypothesis is generally formulated to look for evidence to support a claim called a research hypothesis? Explain
-
The cost of capital includes the cost not just on the equity of the company but also the debt.Why would a firm wish to reduce its cost of capital? What are some ways to reduce the cost of capital?
-
If (x) 0 on the interval [a, b], the definite integral gives the exact area under the curve between x = a and x = b.
-
Suppose we have a hash set that uses the standard mod hash function shown in the chapter and uses linear probing for collision resolution. The starting hash table length is 11, and the table does not...
-
The java.util package has an interface called ListIterator that extends the Iterator interface and includes additional methods that are specific to iterating through the elements of lists forward or...
-
Write a method called shift that rearranges the elements of a list of integers by moving to the end of the list all values that are in oddnumbered positions and otherwise preserving list order. For...
-
Go to https://www.youtube.com/watch?v=Fp9m4GNwGng to view a brief video on the Brazilian Jet manufacturer Embraer and their use of Critical Chain Project Management for maintenance services. How has...
-
It is sometimes argued that state revenue generated by lotteries is different from tax revenue because people choose to buy lottery tickets. Compare three state revenue sources cigarette excise...
-
Suppose that the demand for personalized license plates and the marginal cost of production in a state is as shown in Figure 16.1. If all the profits go to the government and the state wants to...
Study smarter with the SolutionInn App