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