Haskell语法错误where语句

编程入门 行业动态 更新时间:2024-10-10 19:26:33
本文介绍了Haskell语法错误where语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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语句

本文发布于:2023-10-28 10:36:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536394.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   语法错误   Haskell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!