Haskell:函数checkDirecRio中的非穷举模式

rjzwgtxy  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(162)

下一个文件编译,但当我调用checkDirecRio时,它给出了:函数checkDirecRio中的非穷举模式

checkDirecRio :: Mapa -> Bool
checkDirecRio (Mapa _ []) = True
checkDirecRio (Mapa larg ((Rio x, _) : (_,_)  : t)) = checkDirecRio (Mapa larg t)
checkDirecRio (Mapa larg ((Rio x, _) : (Rio y, _) : t)) | ((x > 0 && y < 0) || (x < 0 && y > 0)) = True
                                                        | otherwise = checkDirecRio (Mapa larg t)

其中结构Mapa被定义为:

type Velocidade = Int

data Mapa =
  Mapa Largura [(Terreno, [Obstaculo])]
  deriving (Show, Read, Eq)

data Terreno
  = Rio Velocidade
  | Estrada Velocidade
  | Relva
  deriving (Show, Read, Eq)

data Obstaculo
  = Nenhum -- ^ nothing
  | Tronco -- ^ wood who can only in Rio being
  | Carro -- ^ car who can only in Estrada being
  | Arvore -- ^ tree who can only in Relva being
  deriving (Show, Read, Eq)

我希望代码能够验证河流Rio是否具有不同的方向,如果两条相邻河流具有相同的方向,则返回False,如果相邻河流具有相反的方向,则返回True

js81xvg6

js81xvg61#

函数checkDirecRio具有不完整的模式,因为它没有涵盖Terreno的所有变体,Terreno除了Rio之外还有2个变体。您应该包含涵盖它们的大小写。例如:

checkDirecRio (Mapa _ (((Estrada _), _):_)) = True
checkDirecRio (Mapa _ ((Relva, _):_)) = False
checkDirecRio (Mapa _ [((Rio _), _)]) = False

相关问题