Embrace!! Partial Application Error

Hugs seems to have a problem with a few unburdened !! in a partial application.

So far, this works fine in GHCi:

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

Declares a syntax error message for ) .

Is this a mistake in the arms?

Adding an extra binding for the second index index statement works though:

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

or

 (([[0]]!!0)!!)0 
+6
source share
1 answer

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

In the arms, the expression should be fexp (or case or do ). Legal expressions such as (a+b+) and (a*b+) are rejected.

Rejection warning

Perhaps this is what FUZxxl talked about in his comment?

Try defining your own function (!!) in ghc and set a right-associative commit for it:

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

Now this line will not 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 (!!) was installed with infixr and is now right-associative. If you are using infixl , this line works fine.

This is a completely separate question from the question you asked. This applies to left and right associativity, while the problem with Hugs is that it simply does not parse an expression like (a+b+) .

+2
source

Source: https://habr.com/ru/post/911683/


All Articles