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
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
ADVERTISEMENT