Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.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 重写'map(f.g.h)x',是否使用不带括号的$?_Haskell - Fatal编程技术网

Haskell 重写'map(f.g.h)x',是否使用不带括号的$?

Haskell 重写'map(f.g.h)x',是否使用不带括号的$?,haskell,Haskell,我想检查一下我们是否不能用$重写没有括号的map(f.g.h)x,因为我找不到方法 以下是我的审判: map (f.g.h) x -> map (f.g.h) $ x -- OK, no benefit -> map $ f.g.h $ x -- wrong as map doesn't take one parameter -> (map $ f.g.h) x -- Ok, no benefit, ugly :-) 我发现唯一优雅的选择就是使用 negate . su

我想检查一下我们是否不能用
$
重写没有括号的
map(f.g.h)x
,因为我找不到方法

以下是我的审判:

map (f.g.h) x
-> map (f.g.h) $ x  -- OK, no benefit
-> map $ f.g.h $ x  -- wrong as map doesn't take one parameter
-> (map $ f.g.h) x  -- Ok, no benefit, ugly :-)
我发现唯一优雅的选择就是使用

negate . sum . tail <$> [[1..5], [3..6]]]
否定。总和尾部[[1..5],[3..6]]
但我想确定我没有跳过上面的一些选项。
如果您定义了该函数,谢谢您

map (f.g.h) x
因此,您可以使用
f处理
x
的每个元素。Gh
,这意味着我们首先对其应用
h
,然后对结果应用
g
,最后对该结果应用
f

但我们也可以使用三个独立的
map
s,如:

map f $ map g $ map h x
怎么样

let u = f.g.h in map u x

没有括号,没有
$

那么
map f$map g$map hx
呢?我看不出
否定…
部分在这里有什么关系?我们还可以定义一个自定义应用程序操作符,比如说
$$
具有右中缀级别和左关联性,这样
f$$x$$y$$z
意味着
((f x)y)z
。不过,我会避免这样做,更喜欢括号。
flip map x$f。Gh
但那很难看。
x>>=返回。FGh
?那么你也不需要
($)
:)相关:。>这是一个让Haskell隐式写括号的技巧,我真的不喜欢这个公式<代码>$只是函数应用程序函数(+这里不相关的hacks),不需要在这里加括号。