Question: 1. Consider the following Python function. How could you rewrite this function in just one line using infinite lists in Haskell? def makeTupleList(ls): mylist =

1. Consider the following Python function. How could you rewrite this function in just one line using infinite lists in Haskell?

def makeTupleList(ls):

mylist = []

counter = 1

for x in ls:

mylist.append((counter, x))

counter += 1

return mylist

2. How would you rewrite this Python code in Haskell, such that the looping condition and the body of the loop would become two separate functions?

def approximatePi(difference):

pi = 0.0

i = 1

pi1 = 5.0

pi2 = 0.0

while((pi1 - pi2) > difference):

pi += 4/i

pi1 = pi

pi -= 4/(i+2)

pi2 = pi

i += 4

return pi

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!