Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please read and answer below functions, remember to include both the (1) function declaration, and (2) function definition and use a multi-line comment at the
Please read and answer below functions, remember to include both the (1) function declaration, and (2) function definition and use a multi-line comment at the top of your function.
I. Write a function sum that that uses recursion to compute the sum of all numbers from I to n. sum': Integer -> Integen 2. Write a function integersqrt that returns the integer square root of a positive integer n. (The integer square root is defined to be the largest integer whose square is less than or equal to n, i.e. the result of incegerSqrt 15 integersqrt Integer -> Integer 3. Incorporate into the above function definitions an error message that will be output if the function is called with a value that is less than or equal to O 4. Write a function exponent' that recursively computes the result of raising some base number, b, to some exponent, e. (eg. 2A8 64). You may not use the A oroperators -you must use recursion. This function will only bc called on an exponent valuc that is a whole number (an integer that is 0 or greater). exponent: Integer -> Integer -> Integer 5. Redefine the built-in infix I| opcrator. Name your new function or. Do not usc guards in your definition, but rather utilize pattern matching. Use the wildcard_ pattern so that you only have two definitions, rather than thc four definitions we would usually write given the truth table of ll 6. Write a unction orderTriple that takes a triple, and returns a version in decreasing order Hint: you may want to define other he per unctions such as max Three middle hree, and mino hree 7. Write a function swap that swaps the characters in a quadruple (4-tuple) in the following way the first elements swaps with the last, and the middle two flip. Only use pattern matching. You may not call any other functions. 8 Write a function asciiNums that takes a String and returns a list of the ascii valucs of characters in that string. 9. Write a function matches that picks out all instances of an integer n from a list. (Example: matches 3 [3.4,5,3] should return [3.3] and matches 3 [45.7] should return D.) 0. Use the matches function in the above problem to write a function element that returns True if an element is a member of a list, False otherwise. (You may not use the elem function that is already defined in Haskell.) or Bool - Bool - Bool orderTriple (Integer, Integer, Integer) -> (Integer, Integer, Integer) swap:: (char, char, Char, char) -> (Char, char, char, char) asciiNums:: String - [Int] matches :: Integer -> [Integer] -[Integer] element: Integer - [Integer] -Bool
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