Reputation: 13541
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?
Upvotes: 3
Views: 120
Reputation: 36349
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.
Upvotes: 2