在where wherements中使用部分函数时解析错误(Haskell)

时间:2017-11-17 16:04:08

标签: haskell

我对Haskell很陌生并且我已经遇到过这个问题几次并且没有在线找到答案。

playDomsHandler (dp1,h1,s1) (dp2,h2,s2) b _
    -- players 1 and 2 both knocking, game ends
    | knockingP b h1 && knockingP b h2 = (b, (s1, s2))
    -- just player 1 knocking, player 2 makes a move
    | knockingP b h1 = playDomsHandler (dp1,h1,s1) (dp2,h2,nScore2) nBoard2 2
    -- just player 2 knocking, player 1 makes a move
    | knockingP b h2 = playDomsHandler (dp1,h1,nScore1) (dp2,h2,s2) nBoard1 1
    where 
      (nBoard1, nScore1) = nextPlay (dp1,h1,s1) b
      (nBoard2, nScore2) = nextPlay (dp2,h2,s2) b

给出解析错误。 ((nBoard2,nScore2)行中的第一个括号)

我之前使用过很多语句,但在使用部分功能时我总是遇到这个问题

任何帮助非常感谢。

1 个答案:

答案 0 :(得分:4)

我打赌你使用制表符而不是空格来缩进。

必须对齐施工地点的陈述。 Haskell解释每个标签,如8个空格,所以如果你搞乱了空格和标签,你的功能可能没有对齐。

如果您的编辑器配置了显示为4个空白区域的选项卡,则表示您没有看到此问题,但Haskell会这样做。

我将-用于空格和\t个标签页(相当于4个空格)。

例如:

where 
----(nBoard1, nScore1) = nextPlay (dp1,h1,s1) b
\t  (nBoard2, nScore2) = nextPlay (dp2,h2,s2) b

这些未对齐,因此Haskell将在(nBoard2, nScore2)

上提供解析错误

我建议始终使用空格而不是制表符。大多数编辑器都可以配置为使用4或8个空白字符替换制表符,因此您不会遇到此问题。