Haskell 为什么不是';是否使用此函数计算整数列表的平均值不起作用?

Haskell 为什么不是';是否使用此函数计算整数列表的平均值不起作用?,haskell,integer,average,Haskell,Integer,Average,我试着做一个函数,将给定列表中的所有数字相加,然后除以6 average :: [Integer] -> Integer average m = (sum m) quot 6 但这是我收到的错误信息: Couldn't match type `Integer' with `(a0 -> a0 -&

我试着做一个函数,将给定列表中的所有数字相加,然后除以6

average :: [Integer] -> Integer
average m = (sum m) quot 6
但这是我收到的错误信息:

Couldn't match type `Integer'                                                                                
              with `(a0 -> a0 -> a0) -> a1 -> Integer'                                                       
Expected type: [(a0 -> a0 -> a0) -> a1 -> Integer]                                                           
  Actual type: [Integer]                                                                                     
In the first argument of `sum', namely `m'                                                                   
In the expression: (sum m) quot 6

您需要在
quot
周围加上反勾号,或者先写

sum m `quot` 6
quot (sum m) 6

您需要在
quot
周围加上反勾号,或者先写

sum m `quot` 6
quot (sum m) 6

在Haskell中,我们将函数名写在参数之前。对于你写的那句话:

quot 17 2
因此,在你的情况下:

quot (sum m) 6

Haskell有一些sytractic sugar,允许您以所谓的中缀符号编写函数。这就是用户mb14所指的内容。

在Haskell中,我们将函数名写在参数之前。对于你写的那句话:

quot 17 2
因此,在你的情况下:

quot (sum m) 6
Haskell有一些sytractic sugar,允许您以所谓的中缀符号编写函数。这就是用户mb14所指的。

(sum m)quot 6
意味着“获取
sum
并将其应用于
m
,然后获取结果函数并将其应用于
quot
,然后获取结果函数并将其应用于
6
”。它与
sum m quot 6
相同。但是,
sum
不返回函数,因此会产生类型错误。
(sum)quot 6
表示“获取
sum
并将其应用于
m
,然后获取结果函数并将其应用于
quot
,然后获取结果函数并将其应用于
6
”。它与
sum m quot 6
相同。但是,
sum m
不返回函数,因此会引发类型错误。