mulang
mulang copied to clipboard
Faulty operator precedence parsing in haskell
The following piece of code:
foo = (even $ 5) || False
(valid)
Gets parsed to the same ast as:
foo = even $ 5 || False
(type error)
This doesn't seem like an easy fix; the haskell parser is parsing the previous two pieces of code to this:
HsInfixApp
(HsParen (HsInfixApp (HsVar (UnQual (HsIdent "even"))) (HsQVarOp (UnQual (HsSymbol "$"))) (HsLit (HsInt 5))))
(HsQVarOp (UnQual (HsSymbol "||")))
(HsCon (UnQual (HsIdent "False")))
HsInfixApp
(HsInfixApp (HsVar (UnQual (HsIdent "even"))) (HsQVarOp (UnQual (HsSymbol "$"))) (HsLit (HsInt 5)))
(HsQVarOp (UnQual (HsSymbol "||")))
(HsCon (UnQual (HsIdent "False")))
The resulting tree hierarchy does not to reflect the operator precedence, it seems that is accounted for at a later stage.