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].
haskell : write a function that reverse the first three element of a list, but not...
haskell : write a function that reverse the first three element of a list, but not the rest. example [1,2,3,4,5,6] == [3,2,1,4,5,6]
How do you make a prediction from a decision tree using confusionMatrix function in rstudio?
How do you make a prediction from a decision tree using confusionMatrix function in rstudio?
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 write a bubble sort function in python that sorts a linked list and...
how do you write a bubble sort function in python that sorts a linked list and if any duplicate are placed bext ti each other?
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT