Question: COMP 141: Haskell Part 3 Instructions: In this exercise, we are going to review a bunch of Haskell structures. (1) Define function second that receives

COMP 141: Haskell Part 3

Instructions: In this exercise, we are going to review a bunch of Haskell structures.

(1) Define function second that receives a list and returns the second element, in the following cases.

(a) Use !! infix operator.

(b) Use head and tail functions.

(2) Deine function secondFromLast that receives a list and returns the second element from last, in the following cases. (a) Use !! infix operator and length function.

(b) Use last and init functions.

(3) Define function secondHalf that receives a list, cuts it in half, and returns the second half. For example, if the input is [1,2,3,4], then the output would be [3,4].

(4) Remember that xs !! n returns the nth element of list xs. Lets define our own version of operator !!, called atIndex, e.g., atIndex 3 [1,2,3,4,5,6] must return 4. Use take and last functions to define atIndex function.

(5) Define function trimList that receives a list and removes the first and last elements of that list. For example, if the input is "abcdef", then the output is "bcde". Define the function, using take and drop functions.

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!