In Haskell, I can easily map a list:
map (\x -> 2*x) [1,2]
gives me [2,4]. Is there any “mapTuple” function which would work like that?
mapTuple (\x -> 2*x) (1,2)
with the result being (2,4).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Searching at Hoogle gives no exact matches for
(a -> b) -> (a, a) -> (b, b), which is the type you require, but it is pretty easy to do yourself:Note, you will have to define a new function for 3-tuples, 4-tuples etc – although such a need might be a sign, that you are not using tuples like they were intended: In general, tuples hold values of different types, so wanting to apply a single function to all values is not very common.