我是Haskell的新手,我不知道哪里出了问题。
data Stmt = If BExpr Stmt
| While BExpr Stmt
| Assign String AExpr
deriving (Eq, Show)
printStmt :: Stmt -> String
printStmt (If e, s1) = "if " ++ (printBExpr e) ++ " {" ++ (printStmt s1) ++ " }"
printStmt (While e, s) = "while" ++ (printBExpr e) ++ "{" ++ (printStmt s) ++ "}"
printStmt (Assign s, e) = s ++ ":=" ++ (printAExpr e)谁能告诉我,我在哪里得到了“无法匹配预期类型”的错误?
发布于 2012-12-23 03:23:16
从模式中删除逗号:
printStmt :: Stmt -> String
printStmt (If e s1) = "if " ++ (printBExpr e) ++ " {" ++ (printStmt s1) ++ " }"
printStmt (While e s) = "while" ++ (printBExpr e) ++ "{" ++ (printStmt s) ++ "}"
printStmt (Assign s e) = s ++ ":=" ++ (printAExpr e)(If e, s1)被解释为一对(二元组)。
发布于 2012-12-23 03:23:44
假设您对printBExpr和printAExpr的定义是正确的,那么您需要删除模式匹配中的逗号:
printStmt (If e s1)
printStmt (While e s)
printStmt (Assign s e)https://stackoverflow.com/questions/14005770
复制相似问题