Question: Answer in HASKELL only! 7) [25 pts] A Haskell list of tuples can be used to represent a lookup table where the first value of

Answer in HASKELL only!

Answer in HASKELL only! 7) [25 pts] A Haskell list of tuples

7) [25 pts] A Haskell list of tuples can be used to represent a lookup table where the first value of each pair is the key and the second value is the associated value. For example: ["a",1),("b",2),("c",3), ("a",4)] (Assume the keys in a lookup table are not necessarily unique.) We want to define a Haskell function (lookup k table) that returns the values for key k in the lookup table. If key k doesn't appear in table it should return empty list. Thus, lookup 3 [(1,"4"),(2,"5"),(1,"3")] returns [] lookup 1 [(1,"4"),(2,"5"),(1,"3")] returns ["4","3"] lookup "5" [("a",1),("b",2),("c",3), ("a",4)) returns [2] (a) (5 pts] What should be the Haskell type of the lookup function ? (Note: The input list does not necessarily "int, String)" or "String, int)" tuples.) (6) [10 pts] Give a recursive definition of the lookup function. (Port of the code is given; complete the following.) lookup k [] lookup k (0) [10 pts] The following is key function is a predicate function that checks whether a given value v is the key in the given pair. iskey v (x,y) = (v==x) For example: (iskey 1 (1,"4")) returns True Now re-define the lookup function using iskey, map, and filter functions. Your solution should not use explicit recursion. You may define additional non-recursive helper function(s) if needed. lookup v iL - 7) [25 pts] A Haskell list of tuples can be used to represent a lookup table where the first value of each pair is the key and the second value is the associated value. For example: ["a",1),("b",2),("c",3), ("a",4)] (Assume the keys in a lookup table are not necessarily unique.) We want to define a Haskell function (lookup k table) that returns the values for key k in the lookup table. If key k doesn't appear in table it should return empty list. Thus, lookup 3 [(1,"4"),(2,"5"),(1,"3")] returns [] lookup 1 [(1,"4"),(2,"5"),(1,"3")] returns ["4","3"] lookup "5" [("a",1),("b",2),("c",3), ("a",4)) returns [2] (a) (5 pts] What should be the Haskell type of the lookup function ? (Note: The input list does not necessarily "int, String)" or "String, int)" tuples.) (6) [10 pts] Give a recursive definition of the lookup function. (Port of the code is given; complete the following.) lookup k [] lookup k (0) [10 pts] The following is key function is a predicate function that checks whether a given value v is the key in the given pair. iskey v (x,y) = (v==x) For example: (iskey 1 (1,"4")) returns True Now re-define the lookup function using iskey, map, and filter functions. Your solution should not use explicit recursion. You may define additional non-recursive helper function(s) if needed. lookup v iL

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 Finance Questions!