我在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