Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Students also viewed these Databases questions