Question
Programming in Haskell: 1. Write a function addFive which takes an Integer list as input and adds 5 to each element the list. Don't forget
Programming in Haskell:
1. Write a function addFive which takes an Integer list as input and adds 5 to each element the list. Don't forget a declaration/type line! (I want you to write this signature yourself, to get some practice.) For example: *Main> addFive [ ] [ ] *Main> addFive [1,6,2,8] [6,11,7,13]
2. Write a function listShuffle :: [a] -> [a] -> [a] that takes two lists as input, and returns a list with the values alternating. When either list is empty, simply concatenate the remaining items of the non-empty list at the back. (If both are empty, then return an empty list!) For example: *Main> listShuffle [1,2,3,4] [9,8] [1,9,2,8,3,4] *Main> listShuffle ['a','b','c'] ['z','y','x','w'] "azbycxw"
3. Write a function indexOf :: [a] -> (a -> Bool) -> Integer which finds the INDEX of the first element in the list which satisfies the given condition function, where we say the head of the list has index 0. If it doesn't appear in the list, return -1. For example: *Main> indexOf [4,2,7,3,1] even 0 *Main> indexOf [4,2,7,3,1] odd 2 *Main> indexOf [4,2,7,3,1] (==12) -1 *Main> indexOf "hello" (=='l') 2 4. Write a function moreThanOne :: Eq a => [a] -> Bool which returns True if its argument contains duplicate elements. For example:
*Main> moreThanOne [1,2,3,4,5] False *Main> moreThanOne [1,2,3,2] True 5. Write a function flipAndCopy :: [a] -> [a] that takes as input a list, and turns that list into a palindrome by duplicating all the elements and putting them at the end of the list, but reversed. For example:
flipAndCopy [1,2,3] = [1,2,3,3,2,1] flipAndCopy ['a','z','e'] = ['a','z','e','e','z','a'] flipAndCopy [ ] = [ ]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started