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?
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...
Implement a non-recursive reverse print of linked list using stack and the main function to test:...
Implement a non-recursive reverse print of linked list using stack and the main function to test: You will need to finish the printReversed_nonrecursive method in ch04.LinkedStack2 class, and the ch04.UseStack2 is the main function to test. public class LinkedStack2<T> extends LinkedStack<T> { private void revPrint(LLNode<T> listRef) { if (listRef != null) { revPrint(listRef.getLink()); System.out.println(" " + listRef.getInfo()); } } public void printReversed() { revPrint(top); } /* use stack to implement non-recursive reverse print */ public void printReversed_nonrecursive() { } public...
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.
How do you define a function that tests if a number is even using lambda calculus?...
How do you define a function that tests if a number is even using lambda calculus? The function should return true if the number is even, and false otherwise.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT