Haskell中的元组映射

apl*_*vin 0 haskell tuples map

我不知道它通常是怎么称呼的,但我需要的是这样的:

f a b c = a + 2 * b + 3 * c

map f [(1,2,3), (4,5,6), (7,8,9)]
Run Code Online (Sandbox Code Playgroud)

即将n元组的列表映射到具有n个单独参数的函数.在Haskell中有没有内置的方法可以做到这一点?

PS:我uncurry刚刚发现,但它似乎没有用3个参数这样做,只有2个.

is7*_*s7s 8

您可以定义自己的功能:

uncurry3 :: (a -> b -> c -> d) -> (a,b,c) -> d
uncurry3 f (a,b,c) = f a b c

map (uncurry3 f) [(1,2,3), (4,5,6), (7,8,9)]
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用uncurryNtuple适合15的元组大小的包:

cabal install tuple

import Data.Tuple.Curry

map (uncurryN f) [(1,2,3), (4,5,6), (7,8,9)]
Run Code Online (Sandbox Code Playgroud)