【发布时间】:2014-07-18 04:09:29
【问题描述】:
我的代码出现此错误:
“解析错误(可能是不正确的缩进或不匹配的括号)”
max3 a b c = if a>b && a>c then show a
else if b>a && b>c then show b
else if c>a && c>b then show c
我需要在 a、b 和 c 之间取较大的数字
编辑:按照建议添加 else 子句后:
max3 a b c = if a>b && a>c then show a
else if b>a && b>c then show b
else if c>a && c>b then show c
else show "At least two numbers are the same"
现在我收到此错误“输入 `if' 时出现解析错误”
按照建议编辑!
已编辑:已解决,我对 shree.pat18 说的守卫做了!太棒了!
【问题讨论】:
-
你需要一个最终的“else”。或者你可以使用
maximum [a,b,c] -
其实是“至少两个数相同”。
-
otherwise与警卫一起工作,而不是 if...else -
那么为什么在我的第一个案例中出现解析错误? x_x
-
您当前的代码加载对我来说很好。也许您的文件中还有其他问题会导致问题?
标签: shree.pat18 parsing haskell