编译Haskell脚本时出错.请帮忙:
main = do
let bmiTell weight height
| weight / height ^ 2 <= 18.5 = "You're underweight, you emo, you!"
| weight / height ^ 2 <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
| weight / height ^ 2 <= 30.0 = "You're fat! Lose some weight, fatty!"
| otherwise = "You're a whale, congratulations!" = "You're a whale, congratulations!"
Run Code Online (Sandbox Code Playgroud)
错误:(3,5)ghc:解析错误(可能是错误的缩进或括号不匹配)
两个问题
正如评论中所说,你的守卫至少需要缩进一个额外的空间(所以管道更加缩进了b)
您需要的不仅仅是块let内部do.例如,您可能想要测试您的功能!
解决了这些问题:
main = do
let bmiTell weight height
| weight / height ^ 2 <= 18.5 = "You're underweight, you emo, you!"
| weight / height ^ 2 <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
| weight / height ^ 2 <= 30.0 = "You're fat! Lose some weight, fatty!"
| otherwise = "You're a whale, congratulations!"
putStrLn $ bmiTell 6 1
Run Code Online (Sandbox Code Playgroud)