2013-06-23 150 views
1

在這段代碼解析錯誤在

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 

我在第一解析«|»

+1

檢查您的縮進。一個標籤是8個空格。 – chirlu

+0

@chirlu,我使用4個空格。 – row248

+8

我認爲你的警衛需要經過鄰居的開始 – DiegoNolan

回答

4

守衛必須比他們的一部分功能的名稱,以進一步縮進,例如:

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 

這是因爲以下的地方,你定義一個(本地)功能neighbour,這也在也跟着佈置原則;如果守衛在左邊,那麼它不是neighbour定義的延續。在看起來像這樣的文件中,您會得到相同的錯誤:

neighbour (p,q) 
| b == p = Just q