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
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
IN HASKELL func5 :: (Int -> Int) -> Int -> (Int, Int) func5 f x =...
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 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)) 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.
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...
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...
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...
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
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...
(5.00 Points) 11 - The function prototype double mySqrt(int x); defines a function called a) double which calculates square roots b) mySqrt which takes an integer as an argument and returns a double c) mysqrt which takes an argument of type x and returns a double d) mysqrt which takes a double as an argument and returns an integer