0

我正在尝试为我正在开发的游戏构建一个小型错误检查器,但我不确定如何将数据类型作为参数传递。这是我想要做的这是我的数据参数所在的文件

-- | Represents the type of move played in a 'GameState'.
data Played = Played ((Int, Int), (Int, Int)) -- ^ A "normal" move.
            | Passed                          -- ^ A (legal) pass.
            | Goofed ((Int, Int), (Int, Int)) -- ^ An illegal move, penalty applied.
            | Init                            -- ^ No one has moved yet.
            | UpgradedPawn2Knight (Int,Int)   -- ^ A pawn reached the other side when <2 knights.
            | PlacedPawn ((Int, Int), (Int, Int)) -- ^ A pawn that's been placed in any empty space after having reached the far end of the board.
            | BadPlacedPawn ((Int, Int), (Int, Int)) -- ^ A strategy has attempted to do a pawn placement, but chose an invalid location.

这是我的代码尝试实现基于这些游戏状态的功能

prevPenalty :: Played -> Int
prevPenalty Init = 0
prevPenalty Goofed ((a, b),(c, d)) = 1
prevPenalty Passed ((a, b),(c, d)) = 0


currentPenalty :: Played -> Int
currentPenalty Goofed ((a, b),(c, d)) = 1 + prevPenalty
currentPenalty Passed ((a, b),(c, d)) = 0 + prevPenalty

但是,在编译时会出现此错误

Penalty.hs:22:1:
    Equations for ‘prevPenalty’ have different numbers of arguments
      Penalty.hs:22:1-20
      Penalty.hs:23:1-38

Penalty.hs:28:1:
    Couldn't match expected type ‘t0 -> t1’ with actual type ‘Int’
    The equation(s) for ‘currentPenalty’ have two arguments,
    but its type ‘Played -> Int’ has only one

我不知道如何解决这个问题......有人有什么建议吗?

4

0 回答 0