gpt4 book ai didi

haskell - 拥抱!!部分应用程序错误

转载 作者:行者123 更新时间:2023-12-03 14:40:44 27 4
gpt4 key购买 nike

拥抱似乎有几个不抱的问题!!在部分应用程序中。

虽然这在 GHCi 中运行良好:

([[0]]!!0!!)0

Hugs 报告 ) 的语法错误。 .

这是拥抱中的错误吗?

为第二个列表索引运算符添加一个额外的大括号虽然有效:
(([[0]]!!)0!!)0

或者
(([[0]]!!0)!!)0

最佳答案

这是 Hugs 中的一个已知问题。来自 Hugs 98 Users Guide表达式部分:

In Hugs, the expression must be an fexp (or case or do). Legal expressions like (a+b+) and (a*b+) are rejected.



题外话提醒

也许这就是 FUZxxl在他的评论中谈论的是什么?

尝试定义自己的 (!!) ghc中的函数并将其设置为具有右关联固定性:
import Prelude hiding ((!!))
infixr 5 !! -- infixr will make it right associative
(!!) a b = head . drop b $ a

现在该行在 ghci 中不起作用任何一个!
ghci> :t ([[0]] !! 0 !!)

<interactive>:1:1:
The operator `!!' [infixr 5] of a section
must have lower precedence than that of the operand,
namely `!!' [infixr 5]
in the section: `[[0]] !! 0 !!'

因为 (!!)已设置为 infixr现在是右结合的。如果您使用 infixl ,那条线工作正常。

这是与您提出的问题完全不同的问题。这是关于左与右关联性的,而 Hugs 的问题在于它不解析像 (a+b+) 这样的表达式。 .

关于haskell - 拥抱!!部分应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9874226/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com