Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(a) elemAll 10% Write a Haskell function elemAll that takes two lists as input and returns True if all elements in the first list
(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 [ ]
Step by Step Solution
★★★★★
3.46 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started