Vec2.hs: 33:27:解析输入错误'='
我在这里写的代码如下。错误指向第二项 vec2Normalize iLength = ... 我没有看到语法错误
- 获得v的逆长度并将其乘以它 - 得到v的归一化形式 vec2Normalize :: Vec2 - > Vec2 vec2Normalize v @(x,y)=(x * iLength,y * iLength)其中length = vec2Length v iLength = if长度== 0 then 1 else(1 / length )解决方案
由于您不提供完整的代码,但是这个错误可能表明你的行 iLength = ... 没有正确缩进;实际上, iLength 开始于前一行的 length = 的 right 。
您的原始文件是否使用制表符而不是空格进行缩进?如果是这样,请注意,Haskell总是将选项卡解释为跨越8列。因此,例如,
< TAB>其中,长度= ... < TAB>< TAB> < SPACE>< SPACE> iLength = ...会被解释为
where length = ... iLength = ...因此会导致错误,即使您的编辑器在使用4列选项卡时可能会显示正确对齐的行。
I'm writing some Haskell code to learn the language, and I've run into the syntax error:
Vec2.hs:33:27: parse error on input '='
The code I've written here is below. The error is pointing at the 2nd term in vec2Normalize iLength = ... I don't see the syntax error
-- 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)解决方案
Some guessing involved since you don’t provide the complete code, but this error could indicate that your line iLength = ... is not properly indented; actually, that the iLength starts to the right of the length = on the line before.
Does your original file use tabs instead of spaces for indentation? If so, be aware that Haskell always interprets a tab as spanning 8 columns. So, e.g.,
<TAB>where length = ... <TAB><TAB><SPACE><SPACE>iLength = ...would be interpreted as
where length = ... iLength = ...thus causing the error, even though your editor might show the lines properly aligned if it uses 4-column tabs.
更多推荐
Haskell语法错误where语句
发布评论