Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

Students also viewed these Databases questions