下一个文件编译,但当我调用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
1条答案
按热度按时间js81xvg61#
函数
checkDirecRio
具有不完整的模式,因为它没有涵盖Terreno
的所有变体,Terreno
除了Rio
之外还有2个变体。您应该包含涵盖它们的大小写。例如: