Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi! I have been working on some homework for a programming languages course and

ID: 3680441 • Letter: H

Question

Hi!

I have been working on some homework for a programming languages course and I am stuck. The programming language is Haskell, this is problem one:

1.   (a) Define a function addFirstA which takes a list of integers and returns a list in which each element is the sum of the first and corresponding elements of list, without using higher-order functions. For example: addFirst [4,3,2,1] = [8,7,6,5]

(b) Repeat the problem in part a and write addFirstB , but you should use a higher-order function.

What would be the proper answer to this? Thanks!

Explanation / Answer

Please find below the function addFirstA which returns a list in which each element is the sum of the first and corresponding elements of list:

(define (addlist x) ; adds the first element of a list to all other elements
(define a (car x)) ; a is definitely the first part of the list
(map (lambda (y) (+ a y)) x) )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote