Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 如何创建一个可以接受一个函数元组而不是一个函数的fmap?_Haskell_Category Theory - Fatal编程技术网

Haskell 如何创建一个可以接受一个函数元组而不是一个函数的fmap?

Haskell 如何创建一个可以接受一个函数元组而不是一个函数的fmap?,haskell,category-theory,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") 一般来说,对于从A->T_i开始的函数,对于某些变量类型T_i和固定类型A,我认为这只是A的简化,至少对于一个2元组的1参数函数来说,看到一个超出2元组的泛化将非常好。您可以使用uncurry&&&&,如下所示: &

这可能是一种构造方法

是否有一种理想的标准实现方式

 f :: Int -> Int
 f x = 2*x
 g :: Int -> String
 g x = show x
 h = (f, g)
 fmap h 5 -- results in: (10, "5")
一般来说,对于从A->T_i开始的函数,对于某些变量类型T_i和固定类型A,我认为这只是A的简化,至少对于一个2元组的1参数函数来说,看到一个超出2元组的泛化将非常好。

您可以使用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")
您可以使用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")

@切普纳:谢谢,修正了,我想如果你想要一个泛化,你需要一个异构列表,假设你有a->b_1,a->b_2…,a->b_n->a->b_1,b_2,…,b_n@chepner谢谢,修正了,我想如果你想要一个泛化,你需要一个异构列表,假设你有a->b_1,a->b_2…,a->b_n->a->b_1,b_2,…,b_n