我正在写一些Haskell代码来学习语言,我遇到了语法错误:
Vec2.hs:33:27: parse error on input '='
我在这里写的代码如下.错误指向第二个术语vec2Normalize iLength = ...我没有看到语法错误
-- Get the inverse length of v and multiply the components by it
-- Resulting in the normalized form of v
vec2Normalize :: Vec2 -> Vec2
vec2Normalize v@(x,y) = (x * iLength, y * iLength)
where length = vec2Length v
iLength = if length == 0 then 1 else (1 / length)
Run Code Online (Sandbox Code Playgroud)
由于您没有提供完整的代码,因此涉及一些猜测,但此错误可能表示您的行iLength = ...没有正确缩进; 实际上,该iLength开始对权的length =对前行.
您的原始文件是否使用制表符而不是缩进空格?如果是这样,请注意Haskell始终将选项卡解释为跨越8列.所以,例如,
<TAB>where length = ...
<TAB><TAB><SPACE><SPACE>iLength = ...
Run Code Online (Sandbox Code Playgroud)
将被解释为
where length = ...
iLength = ...
Run Code Online (Sandbox Code Playgroud)
因此导致错误,即使您的编辑器可能显示正确对齐的行,如果它使用4列选项卡.