haskell-suite / haskell-src-exts

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

Support TypeInType #414

Closed AshleyYakeley closed 5 years ago

AshleyYakeley commented 6 years ago

With TypeInType enabled, kinds are simply types. So I've made type Kind = Type.

Parsing is trickier. The main problem is that * can be either a kind or a type operator, and this makes parsing tricky. To avoid a reduce/reduce conflict, I've parameterized the type-related parsing rules so as to assume that * is a type operator in "type context" and is a kind (type) in "kind context". This isn't perfect but AFAICT should not cause backwards compatibility problems.

mpickering commented 6 years ago

Thank you @AshleyYakeley. This was something that badly needed fixing. As you observed there is a problem that GHC only resolves which * you mean in the renamer. Therefore I think your solution is the least bad even if I hate it when the parser code diverges from the GHC code base.

mpickering commented 6 years ago

@AshleyYakeley Do you have an example which demonstrates the reduce/reduce conflict you were talking about? This does add quite a bit of complexity to the parser that I would rather avoid.

AshleyYakeley commented 6 years ago

Hmm, I don't have that code anymore. However, if you try to eliminate my parser parameterisation, so that the same code can parse both *-as-type and *-as-type-operator, you should run in to it.

AshleyYakeley commented 6 years ago

I'm guessing the problem is that, for example, type T = A * B is ambiguous, as the * could be either an operator, or a parameter to A.

AshleyYakeley commented 5 years ago

TBH, unless you can see a better way (I couldn't), I recommend you bite the bullet of additional parser complexity.

mpickering commented 5 years ago

Well ok. This project is so much effort to maintain anyway and this will make it not much worse.