use*_*822 0 syntax parsing haskell
temperatura :: Float->Float
temperatura qCalor
| qCalor == 0 = 10
| 0 < qCalor < 3 = 30--fTem1
| 3 <= qCalor <= 9 = 50
| qCalor > 9 = 60--fTemp2
| 15 <= qCalor <= 24 = 150
| 24 < qCalor <= 27 = 170--fTemp3
| otherwise = "Nao existe temperatura correspondente a esse calor no grafico!"
Run Code Online (Sandbox Code Playgroud)
优先级解析错误为什么会这样?
首先,在提出问题时,发布实际错误是有帮助的.这是我得到的:
test.hs:3:7:
Precedence parsing error
cannot mix `<' [infix 4] and `<' [infix 4] in the same infix expression
test.hs:4:7:
Precedence parsing error
cannot mix `<=' [infix 4] and `<=' [infix 4] in the same infix expression
test.hs:6:7:
Precedence parsing error
cannot mix `<=' [infix 4] and `<=' [infix 4] in the same infix expression
test.hs:7:7:
Precedence parsing error
cannot mix `<' [infix 4] and `<=' [infix 4] in the same infix expression
Run Code Online (Sandbox Code Playgroud)
现在,问题基本上是<(和其他比较运算符)实际上只是二进制函数 - 带有两个参数的函数.编译器告诉您它无法知道如何在表达式中放置括号,因为这些函数具有相同的优先级.举个例子,这个:
| 0 < qCalor < 3 = 30
Run Code Online (Sandbox Code Playgroud)
编译器不知道是否就意味着(0 < qCalor) < 3或0 < (qCalor < 3).在任何情况下,该行都没有合理的输入.
我建议使用像(0 < qCalor) && (qCalor < 3)(或者更好)这样的函数(可能有一个内置的函数):
betweenNums a b c = (a < b) && (b < c)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2183 次 |
| 最近记录: |