以下是我遇到问题的代码:
-----Function to test the postcondition----------------------------------
testPost :: Name -> Int -> [a] -> [b] -> IO ()
testPost _ _ [] [] = putStrLn "Test finished correctly"
testPost f_name n (t:ts) (o:os) = if (not aux_bool) then
do putStr ("Failed on function " ++ (nameBase f_name) ++ " with inputs ")
print ts
putStr " and output "
print os
putStrLn ""
else do
do testPost f_name n ts os
where aux_bool = post f_name n t o
编译器只是抱怨第一行:
C:\Users\pegartillo\Desktop\TFG\CaseGenerator\src\UUTReader.hs:205:1:
parse error (possibly incorrect indentation or mismatched brackets)
我正在使用模板haskell库,这就是它出现Name数据类型的原因。
答案 0 :(得分:1)
要让它编译,至少:
import Control.Monad (when)
newtype Name = Name { nameBase::String}
post _ _ _ _ = True
-----Function to test the postcondition----------------------------------
testPost :: (Show a,Show b) => Name -> Int -> [a] -> [b] -> IO ()
testPost _ _ [] [] = putStrLn "Test finished correctly"
testPost f_name n (t:ts) (o:os) = do
when (not aux_bool) $ do
putStr ("Failed on function " ++ (nameBase f_name) ++ " with inputs ")
print ts
putStr " and output "
print os
putStrLn ""
testPost f_name n ts os
where
aux_bool = post f_name n t o
if-then-else
和do
的布局可能会变得棘手。就个人而言,如果可以的话,我尽量避免混合它们。可能有所帮助的是将每个块的主体拉出到自己的表达式中,以便在尝试调试时简化操作。