为什么这个计算整数列表平均值的函数不起作用?



我正在尝试制作一个函数,从给定列表中加起来所有数字,然后将其除以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

在haskell中,我们在参数之前编写函数名称。对于 quot 您写:

quot 17 2

因此,在您的情况下:

quot (sum m) 6

HASKELL具有一些Sytactic糖,可让您在所谓的Infix 符号中编写功能。这是用户MB14所指的。

最新更新