0
我試圖做一個函數,它從一個給定的名單加起來所有的數字,然後由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
'(sum m)quot 6''意爲「take'sum'並將其應用於'm',然後將得到的函數應用到'quot',然後將得到的函數應用到'6 '」。它與「總和」6「相同。但是,sum m不會返回函數,所以會引發類型錯誤。 – chi