关于bmiTell,我得到parse error
为什么会这样?
Prelude> :{
Prelude| let bmiTell :: Double -> Double -> String
Prelude| bmiTell weight height
Prelude| weight / height ^ 2 <= 18.5 = "You're underweight, you emo, you!"
Prelude| weight / height ^ 2 <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
Prelude| weight / height ^ 2 <= 30.0 = "You're fat! Lose some weight, fatty!"
Prelude| otherwise = "You're a whale, congratulations!"
Prelude| :}
<interactive>:19:1: parse error on input `bmiTell'
答案 0 :(得分:3)
你的缩进正在抛弃解析器。看看这个:
Prelude> :{
Prelude| let bmiTell :: Double -> Double -> String
Prelude| bmiTell weight height = undefined
Prelude| :}
<interactive>:6:1: parse error on input `bmiTell'
Prelude> :{
Prelude| let bmiTell :: Double -> Double -> String
Prelude| bmiTell weight height = undefined
Prelude| :}
Prelude>
答案 1 :(得分:2)
您正在尝试在函数定义中使用guards,所以
weight / height ^ 2
应该是
| weight / height ^ 2
其他人也很相似。
正如@DiegoNolan在评论中指出的那样,你真的应该把这个定义放在一个源文件中并加载到ghci
。