Question
I would some help with this which is to You must implement your functions recursively. In the event that Haskell has a function that does
I would some help with this which is to You must implement your functions recursively. In the event that Haskell has a function that does what you are asked to do, you may not simply call the Haskell function you must implement the functionality yourself. (E.g. no fair calling elem if you are asked to determine whether an item is a member of a list.) If you have an idea as to how to approach a problem, but cannot figure out how to express it in Haskell, describe your idea and I will consider it for partial credit. Be sure to provide type declarations for each of your functions, in addition to the function itself. Write all of your functions in a single Haskell file, which you will submit via Blackboard. You can load your file into the GHCi interactive system using: l. You do not need to provide a main or other interface. Your functions will be tested by loading them into an interactive session and passing them through HUnit tests. Thanks for the help. I just need the solution to how we write each function in Haskell.
3. (3 points) Write a function getNth that takes an Int (n) and a list and returns the nth element of the list, counting from 1. (Yes, this is very similar to the indexing operator, !!, no you may not use !!) Consider the cases where the list is too short or the index is nonsensical, and do something appropriate like throw an error. For example: getNth 3 [355, 2017, 55, 10] => 55 getNth 9 [355, 2017, 55, 10] -> error 4. (3 points) Write a function reachSum that takes an Int as the target sum, which will be positive, and a list of positive Int values. You should return an Int (n) such that the sum of the first n elements is less than or equal to the target, but the sum of the first n+1 elements is greater than the target. If the sum of the list overall is less than the target, return the number of elements in the list. For example: reach Sum 40 [12, 27, 13, 10) -> 2 reach Sum 100 [12, 27, 13, 10] => 4 reach Sum 10 (12, 27, 13, 10] -> 0 3. (3 points) Write a function getNth that takes an Int (n) and a list and returns the nth element of the list, counting from 1. (Yes, this is very similar to the indexing operator, !!, no you may not use !!) Consider the cases where the list is too short or the index is nonsensical, and do something appropriate like throw an error. For example: getNth 3 [355, 2017, 55, 10] => 55 getNth 9 [355, 2017, 55, 10] -> error 4. (3 points) Write a function reachSum that takes an Int as the target sum, which will be positive, and a list of positive Int values. You should return an Int (n) such that the sum of the first n elements is less than or equal to the target, but the sum of the first n+1 elements is greater than the target. If the sum of the list overall is less than the target, return the number of elements in the list. For example: reach Sum 40 [12, 27, 13, 10) -> 2 reach Sum 100 [12, 27, 13, 10] => 4 reach Sum 10 (12, 27, 13, 10] -> 0Step 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