在其中使用部分函数时分析错误(Haskell) [英] Parse errors when using partial functions in where statments (Haskell)
问题描述
我对Haskell很新,我遇到过几次这样的问题,并且没有在网上找到答案。
I'm pretty new to Haskell and I've run into this problem a few times and have had no luck finding answers online.
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)行中的第一个括号)
Gives a parse error. (The first bracket in the (nBoard2, nScore2) line)
我以前使用过很多语句,但在使用部分函数时似乎总是遇到此问题
I've used where statements plenty before but I always seem to run into this problem when using partial functions
非常感谢任何帮助。
推荐答案
我打赌您使用的是制表符而不是空格来缩进。
I bet you are using tabs instead of white space for indentation.
结构中的陈述必须一致。 Haskell将解释每个标签,如8个空格,所以如果你正在搞乱空格和标签,可能你的函数没有对齐。
The statements in the where construction must be aligned. Haskell interprets every tabs like 8 white space, so if you are messing with white space and tabs maybe your functions are not aligned.
如果你的编辑器配置了选项卡, 4空白区域,你没有看到这个问题,但Haskell确实。
If your editor is configured with tabs showing to 4 white space, you are not seeing this problem, but Haskell does.
我将使用 -
作为空格和 \ t
por选项卡(等于4个空格)。
I will use -
for white space and \t
por tabs (equal to 4 white space).
例如:
where
----(nBoard1, nScore1) = nextPlay (dp1,h1,s1) b
\t (nBoard2, nScore2) = nextPlay (dp2,h2,s2) b
这些不是对齐的,所以Haskell将在(nBoard2,nScore2)上给出解析错误
These are not aligned, so Haskell will give parse error on (nBoard2, nScore2)
我建议始终使用空格而不是制表符。大多数编辑器可以配置为替换4或8个空格字符的标签,所以你不会遇到这个问题。
I recomend to use always white space instead of tabs. Most editors can be configured to replace tabs with 4 or 8 white space characters, so you will not get this problem.
这篇关于在其中使用部分函数时分析错误(Haskell)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!