0
我寫了一個名爲「baby.hs」用以下代碼爲什麼helloworld haskell片段無法加載?
bmiTell :: => Double -> String
bmiTell bmi
| bmi <= 1 = "small"
| bmi <= 10 = "medium"
| bmi <= 100 = "large"
| otherwise = "huge"
當我在GHCi
加載該文件,它抱怨是這樣的:
ghci>:l baby.hs
[1 of 1] Compiling Main (baby.hs, interpreted)
baby.hs:1:12: parse error on input ‘=>’
Failed, modules loaded: none.
ghci>
如果我刪除=>
,它不工作之一:
bmiTell :: Double -> String
bmiTell bmi
| bmi <= 1 = "small"
| bmi <= 10 = "medium"
| bmi <= 100 = "large"
| otherwise "huge"
錯誤信息:
ghci>:l baby
[1 of 1] Compiling Main (baby.hs, interpreted)
baby.hs:7:1:
parse error (possibly incorrect indentation or mismatched brackets)
Failed, modules loaded: none.
有沒有人有這方面的想法?
'這是行不通的either'你是什麼意思? – thefourtheye
@thefourtheye添加了「錯誤信息」,它只是說'解析錯誤' –
爲什麼你要在你的類型簽名中加入一個約束符號'=>'?沒有用。另一個問題是在'else'之後缺少'='。 – AJFarmar