我在Haskell中撰寫並希望在函數中打印語句並調用另一個函數,我不知道爲什麼這不起作用。有人可能會告訴我我做錯了什麼或提供更合理的解決方案嗎?Haskell打印聲明
我的錯誤是:
Couldn't match expected type `[a0]' with actual type `IO()'
In the return type of a call of `putStrLn'
In a stmt of a 'do' block: putStrLn "Missing closing bracket"
In the expression:
do { putStrLn "Missing closing bracket";
evaluate_input }
代碼:
bracket_content [] 0 = []
bracket_content (first:rest) counter
| is_open_bracket first = first : bracket_content rest (counter + 1)
| is_close_bracket first = first : bracket_content rest (counter - 1)
| counter == 0 = []
| otherwise = first : bracket_content rest counter
bracket_content _ _ = do putStrLn "Missing closing bracket" --error here
evaluate_input
evaluate_input :: IO()
evaluate_input = do
putStrLn "Enter Expression or 'q' to exit calculator: "
expression <- getLine
case expression of
a:as -> return a
unless (expression == ['q']) $ evaluate_expression expression
where evaluate_expression e = do
putStrLn . show $ calculate e
evaluate_input
您將不再提供關鍵信息。什麼是錯誤?什麼是功能類型? – Pubby 2013-02-26 03:30:38
對不起,我不清楚我編輯我的帖子上面。基本上我只想打印錯誤消息,然後調用evaluate_input。 – CodeNewbie 2013-02-26 03:46:56
來自錯誤的所有代碼片段似乎都正常工作,您需要包含更多代碼。 – crockeea 2013-02-26 04:00:35