Hugs !! Partial Application Bug

混江龙づ霸主 提交于 2019-12-07 02:01:05

问题


Hugs seems to have a problem with several non-enbraced !! in a partial application.

While this works fine in GHCi:

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

Hugs reports a syntax error for the ).

Is this a bug in Hugs?

Adding an extra brace for the second list index operator works though:

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

or

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

回答1:


This is a known issue in Hugs. From the Hugs 98 Users Guide section on Expressions:

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

Digression Alert

Maybe this is what FUZxxl was talking about in his comment?

Try defining your own (!!) function in ghc and set it to have right-associative fixity:

import Prelude hiding ((!!))
infixr 5 !! -- infixr will make it right associative
(!!) a b = head . drop b $ a

Now that line won't work in ghci either!

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 !!'

Because (!!) has been set with infixr and is now right-associative. If you use infixl, that line works fine.

This is a completely separate issue from the question you asked though. This is about left vs right associativity, whereas the problem with Hugs is that it just doesn't parse an expression like (a+b+).



来源:https://stackoverflow.com/questions/9874226/hugs-partial-application-bug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!