Haskell I';“我得到哈斯克尔”;分析错误(可能是不正确的缩进或不匹配的括号)“;我看不到什么';这是不对的

Haskell I';“我得到哈斯克尔”;分析错误(可能是不正确的缩进或不匹配的括号)“;我看不到什么';这是不对的,haskell,Haskell,下面是我实际遇到问题的代码: -----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_

下面是我实际遇到问题的代码:

-----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 data type的原因。

要编译它,至少:

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
的布局可能会变得棘手。就我个人而言,如果可以的话,我会尽量避免把它们混在一起。在尝试调试时,可以帮助您将每个块的主体提取到它们自己的表达式中以简化事情。

为什么一行有两个
do
s?一个应该是else子句的一部分,而第二个在else之外。可能不是吗?不是。一个空的do块本身就是一个错误。那么它应该是什么呢?else do return()@PedroGarcíaCastillo应该
testPost f_name n ts os
包含在这两种情况下,还是只包含在
else
路径中?如果<代码> EX/<代码>应该是空的,我会考虑使用<代码>控件.Munad。当而不是<代码> > 。多谢,我根本不知道什么时候,但它确实是有用的,正如你所说的,如果要混合IF和DO的代码,如果< /COD>不是压痕敏感的,那么一个语句包含了“<代码>如果 >的布局。没有意义。@user2407038我承认我不知道确切的规则,但是当在
do
块中使用时,我不得不调整
if-then-else
的布局。