均值(haskell)
想写一个求均值的函数。
写成
mean x = sum(x) / length(x)总是类型不对,double/int除不了。
没办法,还没有看到怎么转换类型,只有重写了一个length。
mean x = sum(x) / len(x)
where len [] = 0.0
len x = 1.0 + len (tail x)
想写一个求均值的函数。
写成
mean x = sum(x) / length(x)总是类型不对,double/int除不了。
没办法,还没有看到怎么转换类型,只有重写了一个length。
mean x = sum(x) / len(x)
where len [] = 0.0
len x = 1.0 + len (tail x)
暂无评论。
评论功能维护中,当前仅展示历史评论。