Question: Haskell coding question Please answer the following question Question 1 In this question, you are asked to implement two functions that sum the elements in

Haskell coding question

Please answer the following question

Haskell coding question Please answer the following question Question 1 In this

Question 1 In this question, you are asked to implement two functions that sum the elements in a list of integers. Their type signatures are: sum1 :: [Int] -> Int sum2 :: [Int] -> Int If your code is correct, you should be able to load it into GHCI and execute code similar to the following without errors: >>> :1 question1.hs [1 of 1) Compiling Main ( question1.hs, interpreted ) Ok, one module loaded. >>> sum1 [] 0 >>> sum1 [1..10] 55 >>> sum2 [] 0 >>> sum2 (1. .10] 55 (a) Implement the sum1 function without help from any standard library functions other than the standard addition operator. To do this, you need to think recursively: What is the sum of the empty list of elements? Given a list x:xs with a head x and a tail xs, how can you recursively define the sum of the elements in this list? This should lead to two equations of the form: sumi [] sumi (x:xs) 1 (b) Use Hoogle to find out about the foldl function. Implement sum2 with the help of foldl

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!