您需要的唯一输入是您得到的成绩编号。这是我迄今为止所拥有的。Haskell中if语句的正确语法
myScore x = if x > 90
then let x = "You got a A"
if 80<x<90
then let x = "you got a B"
if 70<x<80
then let x = "You got a C"
if 60<x<90
then let x = "you got a D"
else let x = "You got a F"
这给了我一个错误“上输入'如果”语法错误”,我也试过:
myScore x = (if x > 90 then "You got an A" | if 80 < x < 90 then "You got a B" | if 70 < x < 80 then "You got a D" | if 60 < x < 70 then "You got a D" else "You got a F")
但也不能工作。
您需要在每个if之前添加else。 – 2013-03-10 01:28:46
在这里使用警卫而不是嵌套'if's会更好。 – hammar 2013-03-10 01:43:27