问题描述
我正在尝试使用haskell代码来查找某人的bmi,为此我正在使用Guards
pls guide me fort his code
bmiTell :: (RealFloat a) => a -> String
bmiTell bmi
| bmi <= 18.5 = " You're underweight!"
| bmi <= 25.0 = "You're supposedly normal!"
| bmi <= 30.0 = "You're fat!"
| otherwise = “Something wrong!"
执行后,它给了我一个输入'|'的解析错误” 请给我一些替代方法
解决方法
缩进在Haskell中很重要。您必须缩进警卫。
bmiTell :: (RealFloat a) => a -> String
bmiTell bmi
| bmi <= 18.5 = " You're underweight!"
| bmi <= 25.0 = "You're supposedly normal!"
| bmi <= 30.0 = "You're fat!"
| otherwise = “Something wrong!"