Question

In: Computer Science

Using Haskell, how do you make a function i.e test that will take a list of...

Using Haskell, how do you make a function i.e test that will take a list of integers and add a 5 to the end of that list

ex:

test [1, 2, 3] will be changed to test [1, 2, 3, 5]

Solutions

Expert Solution

Below is the code for the problem

-- | function to add a number to the end of a list
-- | in our case we take the function name as test
test x = x ++ [5]

-- |main function starts here
main = do
putStrLn "The Final list after adding number 5 at the end of list is:"
-- |here we are calling the function test [1..3]
-- |note [1..3] gives a list of numbers from 1 to 3 i.e [1,2,3]
-- |finally we are printing the return of the function whic is a list
print(test [1..3])

Below is the Screenshots of the output.


Related Solutions

Can someone show me how to write a Haskell function using snd on a list of...
Can someone show me how to write a Haskell function using snd on a list of tuples to create a new list of just the second element in each tuple? Ex. [(‘m’, False), (‘w’, False), (‘n’, True)] would evaluate to [False, False, True].
How do you write an append function for a linked list that is a that has...
How do you write an append function for a linked list that is a that has a O(1) Big O notation in Python? The one given in class is O(n). He recommended using a variable to track the end the list. This is the code I have written so far. I don't think I'm properly defining the tail in the add possibly class Node: def __init__(self, init_data): self.data = init_data self.next = None def get_data(self): return self.data def get_next(self): return...
In statistics, how do you test independence using SAS programming?
In statistics, how do you test independence using SAS programming?
C++ Using what you know about how to take inputs and make outputs to the console,...
C++ Using what you know about how to take inputs and make outputs to the console, create a check printing application. Your application will read in from the user an employee's name and salary, and print out a Console Check similar to the following. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > | $1,000,000 | > > > > ___Pay to the Order of___ Johnny PayCheck > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Using what you know about how to take inputs and make outputs to the console, create...
Using what you know about how to take inputs and make outputs to the console, create a check printing application. Your application will read in from the user an employee's name and salary, and print out a Console Check similar to the following. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > | $1,000,000 | > > > > ___Pay to the Order of___ Johnny PayCheck > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Please only use technique from chapter 1 through 3 in C++ from control structure through object 9th edition
how do you do quantity take offs?
how do you do quantity take offs?
How Do You Pay for Your Health Care? Make a list of the health care services...
How Do You Pay for Your Health Care? Make a list of the health care services that you used last year and estimate the cost of each of those services. Then indicate how these costs were paid, whether by yourself as an out-of-pocket expense or by a health care plan. Write a summary of what you have learned about how your health care expenses are paid.
While conducting an ANOVA test, how do you identify a list of possible contrasts and comparisons?
While conducting an ANOVA test, how do you identify a list of possible contrasts and comparisons?
This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
How do you implement stack by using linked list? No code just explain it.
How do you implement stack by using linked list? No code just explain it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT