Parsing 为什么这个haskell函数会给我一个解析错误?

Parsing 为什么这个haskell函数会给我一个解析错误?,parsing,haskell,Parsing,Haskell,我想说的是,如果字段中所需的位置为1,则返回true,否则返回false。为什么这个代码不起作用 fireShot :: Coordinate -> Field -> Bool fireShot coord Shipfield | nth ( fst(coord)((nth snd(coord)) ShipField) == 1 = True | otherwise = False 防护罩中的支架不

我想说的是,如果字段中所需的位置为1,则返回true,否则返回false。为什么这个代码不起作用

fireShot :: Coordinate -> Field -> Bool
fireShot coord Shipfield
 | nth ( fst(coord)((nth snd(coord)) ShipField) == 1 = True
 | otherwise                                         = False

防护罩中的支架不平衡,打开五个支架,关闭四个支架。此外,变量以小写字母开头,因此它应该(可能)是
shipfield
,而不是
shipfield

我认为使用模式匹配来获得第一和第二坐标可能更好,因为这将使代码更干净。此外,您不需要保护返回
True
False
。您可以将该功能替换为:

fireShot :: Coordinate -> Field -> Bool
fireShot (x,y) shipfield = nth x (nth y shipfield) == 1
fireShot::坐标->字段->布尔

fireShot(x,y)shipfield=n x(n y shipfield)==1
括号看起来不平衡:左5,右4。防护装置中的括号不正确。