3

While in Haskell, the following works:

> (+) `liftM` (Just 3) `ap` (Just 5)
Just 8

Frege hints to use parantheses:

frege> (+) `liftM` (Just 3) `ap` (Just 5)
E <console>.fr:12: invalid expression, none-associative operator liftM
    found on same level as none-associative operator ap
H <console>.fr:12: Use parentheses to disambiguate an expression like a
    liftM b ap c

I found this section in Haskell report:

Expressions involving infix operators are disambiguated by the operator's fixity (see Section 4.4.2). Consecutive unparenthesized operators with the same precedence must both be either left or right associative to avoid a syntax error. Given an unparenthesized expression "x qop(a,i) y qop(b,j) z", parentheses must be added around either "x qop(a,i) y" or "y qop(b,j) z" when i=j unless a=b=l or a=b=r.

In the code above, both the "operators" have no associativity and have the same default precedence so it seems like Frege's behavior is consistent with Haskell report.

Am I understanding this right? Why Frege needs parentheses in this case whereas Haskell is able to disambiguate? or How is Haskell able to disambiguate in this case?

Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52
  • 1
    I *think* both of those should be left-associative (by placing them in *backticks*) so it's ``((+) `liftM` (Just 3)) `ap` (Just 5)`` - maybe Frege does see this differently – Random Dev Jan 07 '16 at 05:51
  • 1
    seems like the question was answered here: https://stackoverflow.com/questions/8139066/haskell-infix-function-application-precedence - to you agree? – Random Dev Jan 07 '16 at 05:57
  • @Carsten Thanks! I actually saw that question but must have overlooked and confused from what I quoted in my question where it says "Given an unparenthesized expression ... parentheses must be added". I checked the question you linked and the Haskell report again, it is clear now. – Marimuthu Madasamy Jan 07 '16 at 16:05

1 Answers1

2

Well, this is because, as it stands, `foo` defaults to non-associativity In Frege, while in Haskell is it left associativity.

This should be corrected in the Frege compiler in order to make it more Haskell compatible.

Cactus
  • 27,075
  • 9
  • 69
  • 149
Ingo
  • 36,037
  • 5
  • 53
  • 100