解析错误在哪里

时间:2013-06-23 17:51:20

标签: 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    = Just p
        | otherwise = Nothing

我先解析«|»

1 个答案:

答案 0 :(得分: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