最终防护中的解析错误(不正确的缩进或括号不匹配)

时间:2013-12-20 04:20:35

标签: haskell

我在以下代码中遇到此错误,但是当我注释掉最后一行时,错误消失了。最后或倒数第二行出了什么问题?

parse error (possibly incorrect indentation or mismatched brackets)

-- | Recursively builds the selector
constructSelector :: String -> Selector -> Maybe [String] -> Maybe [String] -> Selector
constructSelector docType selector inputWords tagsSoFar =
    case docType of
        "tag" -> []
        "todo" -> case inputWords of
                    Nothing -> selector
                    -- when there are no args left to examine, check if we've
                    -- recursively accumulated a list of tags
                    Just ws | ws == [] -> case tagsSoFar of
                                            Nothing -> selector
                                            Just tags -> merge selector [(pack "tags") =: tags]
                            | (head (head ws)) == 'p' && isInteger (tail (head ws)) -> constructSelector docType (merge selector [(pack "priority") =: (read $ (tail (head ws)) :: Int32)]) (remaining ws) tagsSoFar
                            | otherwise (constructSelector docType selector (Just (tail ws)) (Just (head ws):tagsSoFar))

1 个答案:

答案 0 :(得分:7)

你错过了决赛->它应该是

| otherwise -> ...

另外,一个巨大的嵌套条件有点不可读。值得考虑将各个分支重构为适当命名的函数,以使其更具可读性。同样,如果docType不是"todo""tag",那么在运行时打开字符串并崩溃也有点可疑。可能值得做一些像

这样微不足道的事情
data DocType = Todo | Tag

我发现早期进行这些小型安全重构可以节省大量的调试时间。