如何创建一个可以采用元组而不仅仅是单个函数的fmap?

bba*_*ker 1 haskell category-theory

这可能是一种构建方式

是否有(理想的标准)完成方式

 f :: Int -> Int
 f x = 2*x
 g :: Int -> String
 g x = show x
 h = (f, g)
 fmap h 5 -- results in: (10, "5")
Run Code Online (Sandbox Code Playgroud)

一般来说,对于从A-> T_i到某些变量类型T_i和固定类型A的函数,我认为这只是BiFunctor的简化,至少是2元组的1参数函数 - 它将是很高兴看到超越2元组的概括.

chi*_*chi 8

您可以使用uncurry (&&&),如下所示:

> import Control.Arrow
> f :: Int->Int ; f x = 2*x
> g :: Int->String ; g x = show x
> h = (f, g)
> uncurry (&&&) h 5
(10,"5")
Run Code Online (Sandbox Code Playgroud)