COMP0002 Haskell LSA Coursework 2018-19
Instructions
Submit answers to all questions in a file called yoursurname-yourstudentID-HaskellLSAcwk.hs. Answer questions as comments if they do not require you to write code. Submit the file via the sub- mission link in the Haskell LSA coursework section of the Moodle 18-19 snapshot of COMP0002. The deadline for submission is 21 August 2019 at 11:55.
When defining functions pay attention to any instructions and always give the type of the function. You may not use any library functions.
Questions
1. Evaluate (foldr (||) False) . (map (=20)) [10,4,6]
2. Explain what is a User defined data type and give an example.
3. Write a function that returns the largest perfect cube less than 10,000
4. Write your own version of the library function foldr1 using recursive function style.
5. badplus :: (Int, Int) -> Int. Use badplus to create an ¡°add 100¡± function that re- turns 100 + n when applied to the number n
6. Write a function that tests whether the values of a function f on inputs 0 to n are all equal.
7. Write a definition and give the type of the factorial function, call it fac, in recursive function
style.
8. Use higher order functions to define a function that takes a list of items in Ord typeclass and returns the maximum of the list.
9. Write a recursive datatype that stores binary trees of integers.
10. Write a function sumTree that sums the integers in your datatype.
1