0

私は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)

ここで「期待されるタイプと一致しませんでした」というエラーが発生する場所を教えてもらえますか?

4

2 に答える 2

4

パターンからコンマを削除します。

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)ペア(2タプル)として解釈されます。

于 2012-12-22T19:23:15.727 に答える
3

printBExprとの定義に問題がないと仮定するとprintAExpr、パターン一致のコンマを削除する必要があります。

printStmt (If e s1)
printStmt (While e s)
printStmt (Assign s e)
于 2012-12-22T19:23:43.660 に答える