2014-04-06 40 views
0

我在以下bmiTell上得到parse error为什么?haskell新手这个CLI有什么问题bmiTell函数

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' 
+2

你应该真的把这个函数长时间地输入到一个文件中,并将其加载到ghci中,而不是尝试将整个东西输入到ghci中。 – DiegoNolan

回答

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> 
2

你试图在你的函数定义中使用guards,所以

weight/height^2 

应该

| weight/height^2 

其他人是相似的。

而@DiegoNolan在评论中指出,你应该把这个定义放在一个源文件中并加载到ghci