我在以下代码中遇到此错误,但是当我注释掉最后一行时,错误消失了。最后或倒数第二行出了什么问题?
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))
答案 0 :(得分:7)
你错过了决赛->
它应该是
| otherwise -> ...
另外,一个巨大的嵌套条件有点不可读。值得考虑将各个分支重构为适当命名的函数,以使其更具可读性。同样,如果docType
不是"todo"
或"tag"
,那么在运行时打开字符串并崩溃也有点可疑。可能值得做一些像
data DocType = Todo | Tag
我发现早期进行这些小型安全重构可以节省大量的调试时间。