In: Computer Science
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]
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.