Question: Note : Complete the following Haskell function definitions. Unless stated otherwise do not use library functions that are not in the Haskell standard prelude. Use

Note : Complete the following Haskell function definitions. Unless stated otherwise do not use library functions that are not in the Haskell standard prelude.

Use the specified function name as your code will be tested by a Haskell function expecting that function name. The testing program may use many more test cases than the ones shown in the specification. So, please test your functions extensively to ensure that you maximise your marks.

A) Write the function insertAt :: Int -> a -> [a] -> [a]. insertAt n x xs will insert the element x into the list xs at position n items from the beginning of xs. In other words, skip n items in xs, then insert the new element. You can assume that n will be a non-negative number. If n is greater than the length of the list xs then add it to the end of the list. For example insertAt 3 - "abcde" ? "abc-de" insertAt 2 100 [1..5] ? [1,2,100,3,4,5] Hint: Use standard prelude functions ++ and splitAt.

B) Write a function uniq :: Eq a => [a] -> [a] that removes duplicate entries from a sorted (in ascending order) list. The resulting list should be sorted, and no value in it can appear elsewhere in the list. For example: uniq [1,2,2] ? [1,2] uniq [1,2,3] ? [1,2,3]

C)Write a function join :: Eq a => [(a,b)] -> [(a,c)] -> [(a,b,c)]. join takes two lists of pairs, and returns a single list of triples. A triple is generated only when there exists a member of both argument lists that have the same first element. The list elements are not sorted. This is the same semantics as the relational algebra natural join operation. For example: join [(2,"S"),(1,"J")] [(2,True),(3,False)] ? [(2,"S",True)] join [(2,"S"),(1,"J")] [(2,1),(2,2),(3,4)] ? [(2,"S",1),(2,"S",2)] Hint: use list a comprehension.

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!