haskell-suite / haskell-src-exts

Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer
Other
193 stars 94 forks source link

Fix parsing of (~) #428

Open yairchu opened 5 years ago

yairchu commented 5 years ago

Bugfix and test for https://github.com/haskell-suite/haskell-src-exts/issues/421 and https://github.com/ndmitchell/hlint/issues/559

mpickering commented 5 years ago

Why does this have to be treated specially rather than as a normal infix operator? What does GHC do here?

yairchu commented 5 years ago

Why does this have to be treated specially rather than as a normal infix operator?

That's a good question :) I'm not intimately familiar with haskell-src-exts nor GHC, so honestly I don't know for sure. Maybe if I knew why FunCon required special treatment I'd have a better direction on answering it.

I extrapolated on haskell-src-exts's treatment for (->), which is also a special built-in type operator in Haskell, and just made the treatment for (~) consistent with it.

If you think that this isn't the right fix and have a suggestion for a different approach I'll gladly try implementing it.

mpickering commented 5 years ago

The way to tell what is the right thing to do is look at how GHC implements it in its parser.

yairchu commented 5 years ago

Perhaps @niklasbroberg which implemented FunCon this way can offer insight into why it needs to be treated specially, and whether he thinks that reasoning should also apply to ~?

(not in any way disagreeing with the above claim that the GHC implements it is the right thing to do, just looking for possible shortcuts instead of going into GHC's code)