Haskell,我无法摆脱可能的缩进错误

发布于 2024-10-05 05:11:23 字数 746 浏览 0 评论 0原文

我有一个问题,无法找出它是什么。我一遍又一遍地重新缩进,但找不到解决方案。这还有什么可以依赖的吗?

代码:

type Triple = (Prime, Quot, Gen)

correctness :: Triple -> Bool
correctness (p,q,g) = prime && pLength && qLength && divisor && orderq
           where prime   = probablyPrime n 5
                 qLength = q < 2^1024
                 pLength = p < 2^160
                 divisor = (p-1 `mod` q) == 0
                 orderq  = (g^q mod p == 1) && (g > 1)

错误消息(第 94 行对应于“正确性 :: Triple -> Bool”):

crypt.hs:94:0: parse error (possibly incorrect indentation)

编辑:我解决了问题。问题是上述函数中的语法错误。我有 otherwise m_ify m*2 而不是 otherwise = m_ify m*2

I have a problem and cannot find out what it is. I have reindented again over and over, but cannot find the solution. Is there something else this can be dependent on?

Code:

type Triple = (Prime, Quot, Gen)

correctness :: Triple -> Bool
correctness (p,q,g) = prime && pLength && qLength && divisor && orderq
           where prime   = probablyPrime n 5
                 qLength = q < 2^1024
                 pLength = p < 2^160
                 divisor = (p-1 `mod` q) == 0
                 orderq  = (g^q mod p == 1) && (g > 1)

Error Message (line 94 corresponds to "correctness :: Triple -> Bool"):

crypt.hs:94:0: parse error (possibly incorrect indentation)

EDIT: I solved the problem. The problem was a syntax error in an above function. I had otherwise m_ify m*2 instead of otherwise = m_ify m*2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罪歌 2024-10-12 05:11:23

您可能只需要在最后一行的 mod 周围添加反引号即可。这不会导致您报告的缩进错误,但以下内容会为我编译:

n = undefined
probablyPrime = undefined
type Prime = Int
type Quot = Int
type Gen = Int

type Triple = (Prime, Quot, Gen)

correctness :: Triple -> Bool
correctness (p,q,g) = prime && pLength && qLength && divisor && orderq
           where prime   = probablyPrime n 5
                 qLength = q < 2^1024
                 pLength = p < 2^160
                 divisor = (p-1 `mod` q) == 0
                 orderq  = (g^q `mod` p == 1) && (g > 1)

这里唯一的更改(除了前五行)是在最后一行。

You might just need to add backticks around the mod in the final line. This wouldn't cause the indentation error you report, but the following compiles for me:

n = undefined
probablyPrime = undefined
type Prime = Int
type Quot = Int
type Gen = Int

type Triple = (Prime, Quot, Gen)

correctness :: Triple -> Bool
correctness (p,q,g) = prime && pLength && qLength && divisor && orderq
           where prime   = probablyPrime n 5
                 qLength = q < 2^1024
                 pLength = p < 2^160
                 divisor = (p-1 `mod` q) == 0
                 orderq  = (g^q `mod` p == 1) && (g > 1)

The only change here (apart from the first five lines) is in the last line.

一口甜 2024-10-12 05:11:23

Worksforme,直接跳到类型错误。

是第 92 行

type Triple = (Prime, Quot, Gen)

,还是你从其他地方移过来的?有时,错误显示的行号可能晚于实际发生的位置。我会检查第 92 行上方(可能在附近)是否有不匹配的括号。

在某些情况下,一个不可见的 unicode 字符似乎会潜入我的代码中。重新输入有时会起作用。

Worksforme, jumps right into the type errors.

Is line 92 the

type Triple = (Prime, Quot, Gen)

line, or did you move that from somewhere else? Sometimes errors can show up with a line number later than where they actually occur. I would check for mismatched parentheses above line 92 (probably nearby).

And on some occasions an invisible unicode character seems to sneak into my code. Retyping has occasionally worked.

人海汹涌 2024-10-12 05:11:23

尝试:

type Triple = (Prime, Quot, Gen)

correctness :: Triple -> Bool
correctness (p,q,g) = prime && pLength && qLength && divisor && orderq
           where 
              prime   = probablyPrime n 5
              qLength = q < 2^1024
              pLength = p < 2^160
              divisor = (p-1 `mod` q) == 0
              orderq  = (g^q mod p == 1) && (g > 1)

阅读 - http://www.haskell.org/onlinereport/syntax-iso.html 9.3 布局

Try:

type Triple = (Prime, Quot, Gen)

correctness :: Triple -> Bool
correctness (p,q,g) = prime && pLength && qLength && divisor && orderq
           where 
              prime   = probablyPrime n 5
              qLength = q < 2^1024
              pLength = p < 2^160
              divisor = (p-1 `mod` q) == 0
              orderq  = (g^q mod p == 1) && (g > 1)

Read - http://www.haskell.org/onlinereport/syntax-iso.html - 9.3 Layout

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文