无法将预期类型'Double'与haskell中的实际类型'Int'匹配

时间:2016-03-14 21:06:27

标签: haskell

我对Haskell很新,我在下面的代码中找不到错误:

arithmeticMean :: [Double] -> Double
arithmeticMean list = (sum list) / (length list)

我将其输入记事本,将其保存为“mean.hs”,然后尝试运行它。

在GHCI中,我键入:加载均值并得到以下错误:

mean.hs:2:37:
Couldn't match expected type 'Double' with actual type 'Int'
In the second argument of '(/)', namely '(length list)'
In the expression: (sum list) / (length list)
Failed, modules loaded: none.

如果我犯了一个非常微不足道的错误,我道歉,但我没有看到问题。该函数采用一个列表[Double],找到它的总和,得到一个double。 Length获取任何列表并给出int。然后我将一个double除以一个int并返回它。为什么会出错?

0 个答案:

没有答案