Hugs似乎!!在部分应用程序中有几个非enbraced的问题.
虽然这在GHCi中工作正常:
([[0]]!!0!!)0
Run Code Online (Sandbox Code Playgroud)
拥抱报告语法错误).
这是Hugs中的一个错误吗?
为第二个列表索引运算符添加额外的括号可以工作:
(([[0]]!!)0!!)0
Run Code Online (Sandbox Code Playgroud)
要么
(([[0]]!!0)!!)0
Run Code Online (Sandbox Code Playgroud)
这是 Hugs 中的一个已知问题。来自Hugs 98 用户指南有关表达式的部分:
在 Hugs 中,表达式必须是
fexp(orcase或do)。(a+b+)诸如和 之类的法律表达式(a*b+)会被拒绝。
离题警报
也许这就是FUZxxl他的评论中谈论的内容?
尝试定义您自己的(!!)函数ghc并将其设置为具有右关联固定性:
import Prelude hiding ((!!))
infixr 5 !! -- infixr will make it right associative
(!!) a b = head . drop b $ a
Run Code Online (Sandbox Code Playgroud)
现在这条线在任何一个都不起作用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 !!'
Run Code Online (Sandbox Code Playgroud)
因为(!!)已经设置并且infixr现在是右关联的。如果您使用infixl,该行工作正常。
这是与您提出的问题完全不同的问题。这是关于左关联性与右关联性的问题,而 Hugs 的问题是它只是不解析像(a+b+).