Question

IN HASKELL func5 :: (Int -> Int) -> Int -> (Int, Int) func5 f x =...

IN HASKELL

func5 :: (Int -> Int) -> Int -> (Int, Int)
func5 f x = (x, f x)

Using map and the function above, write a function that takes a list of Ints and a function (Int -> Int) and returns a new list of tuples, with the first element being the original element, and the second being the result of the transformation.

e.g. [1,2,3] becomes [(1,1), (2, 4), (3, 9)] if the function passed in returns the square of an element

figured it out myself thank you though

makeATuple :: [Int] -> (Int -> Int) -> [(Int,Int)]
makeATuple x f = map (\x -> func5 f x) x

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The function will be as below:

listToTuple :: [Int] -> (Int -> Int) -> [(Int,Int)]
listToTuple x f = map (\x ->(x ,func5 f x)) x

[1,2,3] becomes [(1,1), (2, 4), (3, 9)] by applying this above function

Add a comment
Know the answer?
Add Answer to:
IN HASKELL func5 :: (Int -> Int) -> Int -> (Int, Int) func5 f x =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 20. [5 points] Rewrite the following ML. function using patterns fun factn. ifn-0 then 1 else n fact (n-1) 21. [S points) Using map function, write an ML function int2real of type int list real l...

    20. [5 points] Rewrite the following ML. function using patterns fun factn. ifn-0 then 1 else n fact (n-1) 21. [S points) Using map function, write an ML function int2real of type int list real list that takes a list of integers and returns the same numbers converted to real. For example, if the input is [1,2,3], the output should be like [1.0,2.0,3.0 22. [5 points] Using foldr function, write a function duplist of type·a list 'a list that takes...

  • Please use Haskell, thank you! For this question, you will implement (under specific constraints) a recursive...

    Please use Haskell, thank you! For this question, you will implement (under specific constraints) a recursive function in Haskell that takes a list of characters as an argument and returns a list that contains only every third element from the argument list in the same order. As a clarifying example, this function, when passed the argument list “ABCDEFGHIJKLMNO”, should return the list “ CFILO”. It should also be noted that your function must work (i.e., not terminate with an error)...

  • Haskell code: checkIfEven :: Int -> Bool x <- readLn let checkIfEven x = (even ((x*3)+1))...

    Haskell code: checkIfEven :: Int -> Bool x <- readLn let checkIfEven x = (even ((x*3)+1)) print checkIfEven    Getting error :  Variable not in scope: checkIfEven :: Int -> Bool, how to fix it? note: function goal is take an int and return a bool. takes the integer multiplies it by 3 and adds 1. if the the outcome is even return true, otherwise false.

  • write the following functions in Picat, Haskell, or python using recursion. 1. member(x, lst): this function...

    write the following functions in Picat, Haskell, or python using recursion. 1. member(x, lst): this function checks to see if x occurs in lst. 2. sorted_list( lst): this function checks if lst is sorted in ascending order 3. Cartesian(xs, ys): this function takes two sets represented as lists, xs and us,, and returns the Cartesian product of the set, I.e a set of all possible pairs (x, y), where x is an element of xs, and y is an element...

  • Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you...

    Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you will be implementing all three, along with three minor functions that can be passed to them. Map The map function takes as arguments a function pointer and a integer vector pointer. It applies the function to every element in the vector, storing the results in-order in a new vector. It then returns a pointer to a new vector. You should pass your square function...

  • ON PYTHON: ''' Design the functions described below. RECALL: With functions that do not return a...

    ON PYTHON: ''' Design the functions described below. RECALL: With functions that do not return a value and print a result to the console, to test you must call the function, run it and visually inspect the result for correctness. With functions that return a value, use the print_test function to provide feedback of the test results at the command line. The print_test function is implemented for you at the bottom of this file. RECALL: floating point arithmetic can lose...

  • Please place all of the following functions (defun …) into a SINGLE .lsp file As such,...

    Please place all of the following functions (defun …) into a SINGLE .lsp file As such, be sure to use the EXACT SAME function names and parameter numbers and orders I provide ​ Write a function ONEFIB that takes a single parameter n and returns the nth Fibonacci number. Write a function ALLFIB that takes a single parameter n and returns a list of the first n Fibonacci numbers. Do not worry about efficiency here. HINT: You can use ONEFIB...

  • please I need it urgent thank in java CISC 3115 Final 3115 F element in the...

    please I need it urgent thank in java CISC 3115 Final 3115 F element in the arraymethod (unction) that is pased an array of in d b) Write a method (function) that is passed an array of in and returns the wmalot lemamt array the smallest element in the c) Write a method (function) that is passed an array of int and returns the average of the in the array

  • Haskell, where it says --your code goes here import Debug.Trace f- search takes the following parameters...

    Haskell, where it says --your code goes here import Debug.Trace f- search takes the following parameters 1. A function to check if the search is done - this function takes: a. the global information for the problerm b. the partial solution - the function returns a bool indicating if solution is complete 2. A function to find the valid next states to go to - this function takes: a. the global information for the problerm b. a partial solution -the...

  • Language: PYTHON Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays...

    Language: PYTHON Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays are 0), int (day of the month 1 to 28) Returns: dates: list of tuples Description: Imagine that you have a favorite weekday, and want to see if certain days fall on that weekday. Using the calendar module from the Python standard library , write a function which takes in a list of tuples formatted like [(month, year), etc.], your favorite weekday, and a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT