我正在尝试实现一个功能,可以检查分数和类中所有分数的列表,然后告诉你通过生成一个字符串你得到的是你高于平均水平。它应该如下面的表达式:
scoreChecker 45 [19,33,40,66,11,77] == "You're better than average!!"
scoreChecker 30 [19,33,40,66,11,77] == "Sorry, you're below the average :-("
scoreChecker 41 [19,33,40,66,11,77] == "Precisely average"
scoreChecker 100 [] == "Sorry, you're not using it correctly"
我的尝试就是这样,但我收到了一个错误:
scoreChecker :: Double -> [Double] -> String
scoreChecker _ [] = "Sorry, you're not using it correctly"
scoreChecker avg (x:xs)
| x <= xs = "You're better than average!!"
| x == xs = "Precisely average"
| otherwise avg = "Sorry, you're below the average :-("
where
scores = [19,33,40,66,11,77]
avg = scores / length
我希望有些专家会帮忙,我第一次学习这门语言。 谢谢大家。
我的输出:
parse error on input `='
答案 0 :(得分:3)
请注意以下内容......
该功能应始终有两个输入......但第二种情况有一个。
xs
是一个列表,avg不是。你如何在这些之间使用(&lt; =)。
您对avg的定义在数学上并不正确。