Haskell 在何处分析错误
在此代码中Haskell 在何处分析错误,haskell,Haskell,在此代码中 neighbours :: CityMap -> District -> [District] neighbours (CM (_,rs)) b = mapMaybe neighbour rs where neighbour (p,q) | b == p = Just q --parse error (possibly incorrect indentation or mismatched brackets) | b == q
neighbours :: CityMap -> District -> [District]
neighbours (CM (_,rs)) b = mapMaybe neighbour rs
where neighbour (p,q)
| b == p = Just q --parse error (possibly incorrect indentation or mismatched brackets)
| b == q = Just p
| otherwise = Nothing
我必须首先解析«|»防护装置的缩进必须比它们所属函数的名称更深,例如:
neighbours :: CityMap -> District -> [District]
neighbours (CM (_,rs)) b = mapMaybe neighbour rs
where neighbour (p,q)
| b == p = Just q
| b == q = Just p
| otherwise = Nothing
这是因为在where之后,您定义了一个(本地)函数neighbor
,它也必须遵循布局规则;如果防护装置更靠左,则它不是邻居定义的延续。您会在一个类似以下内容的文件中遇到相同的错误:
neighbour (p,q)
| b == p = Just q
防护装置的缩进深度必须超过其所属功能的名称,例如:
neighbours :: CityMap -> District -> [District]
neighbours (CM (_,rs)) b = mapMaybe neighbour rs
where neighbour (p,q)
| b == p = Just q
| b == q = Just p
| otherwise = Nothing
这是因为在where之后,您定义了一个(本地)函数neighbor
,它也必须遵循布局规则;如果防护装置更靠左,则它不是邻居定义的延续。您会在一个类似以下内容的文件中遇到相同的错误:
neighbour (p,q)
| b == p = Just q
检查缩进。制表符是8个空格。@chirlu,我用了4个空格。我想你的守卫需要超过缩进的开头。制表符是8个空格。@chirlu,我用4个空格。我想你的卫兵需要超过邻居的开头