Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please code the following Haskell functions, remember to include both the (1) function declaration, and (2) function definition and use single line comments before each
Please code the following Haskell functions, remember to include both the (1) function declaration, and (2) function definition and use single line comments before each function to document what it does.
I. Write a function sum that that uses recursion to compute the sum of all numbers from I to n. sum Integer - Integer 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, ie. the result of integerSart 15 is integersqrt Integer -> Integer . 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 0. 4 write a unction exponent' that recurs ve y computes the result o raising some ase numberb, to some exponent. e e 2 8 : 6 ou may not use e or operators you must se recursion. s unction i oni be called on an exponent value that is a whole number (an integer that is 0 or greater) exponent: Integer -> Integer -> Integer en r tur ee rin Drdin yourn btrather wee paitet mathing Udttr an ohe four definitions we would usually write given the truth table of on: 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 6. Write a function orderTriple that takes a triple, and returns a version in decreasing order. (Hint you may want to define other helper functions such as maxOfThree, middleOfThree, and minOfThree.) . 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 pate tching. You may not call any other functions. 8, write a function as cNums that takes a String and returns a list of the asci values 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 [4.5.7] should return .) 10. 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.)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