Haskell创建列表与地图和应用分部

时间:2017-11-26 14:16:13

标签: haskell

我应该使用地图功能创建一个列表,除以2 来计算平均值,但是我坚持分工部分。

mittelWert (n,m) = map (+n) [m]

这给了我我的清单,但我现在不能把它除以2 ......

我试过了:

mittelWert (n,m) = map (+n) [m] / 2

和此:

mittelWert (n,m) = map (+n) [m] `div` 2

TY。

错误:* Non type-variable argument in the constraint: Fractional [b] (Use FlexibleContexts to permit this) * When checking the inferred type

1 个答案:

答案 0 :(得分:0)

mittelWert (n,m) = map (/2) (map (+n) [m])

两个地图功能完成了这项工作。 将总和纳入列表,然后将列表除以第二个地图函数2