Deterministic operator parsing GHC proposal

Introduce DeterministicOperatorParsing language extension
to determine associativity and precedence from the operator name
instead of from its definition.

I recognize the problem, but I feel like this proposal wiuld really fracture the ecosystem.

I think a better solution would be to get the precedence info from HLS which I presume has access to it.

1 Like

That essentially boils down to reading the imported modules, which e.g. HLint doesnā€™t do on purpose for simplicity/performance reasons. See hlint/README.md at master Ā· ndmitchell/hlint Ā· GitHub

HLS already reads imported modules (via the GHC API), so thatā€™s why Iā€™m assuming it should be able to do it.

And it seems like that is true because there is a fixity plugin that shows the precedence when hovering over an operator: https://github.com/haskell/haskell-language-server/pull/2941

Curiously I was pondering today ā€œIf Iā€™d design a new programming language today, whatā€™d I doā€, and part of my thought process is that Iā€™d made parsing context-independent. Not sure if Iā€™d do it this way (which, incidetially is what Ocaml does, maybe worth mentioning in the proposal), but Iā€™d do something.

For Haskell, my initial gut feeling is that the ship has sailed for such a fundamental change to the syntax I fear.

1 Like

People are talking about making Haskell dependent. Nothing is too late :upside_down_face: .

What other idea did you have in mind though?

But thatā€™s an extension (in the inherent meaning of the word). At least mostlyā€¦

I was briefly pondering not having any precedences at all, and relying on universal (operator-independent) syntactic queues, like spacing or no spacing (i.e. a # b@c has arguably obviously precedences, without knowing # and @), parentheses of course, maybe something like ArgumentDo and then maybe markdown-like bullets. Probably not viable just like that, but a fun thought to entertain.

(I wrote about this some years ago.)

I was briefly pondering not having any precedences at all, and relying on universal (operator-independent) syntactic queues

If you donā€™t already know it, you might like Lewis and Langfordā€™s explanation of using dots to parenthesize expressions :slight_smile: ā€œThe use of dots as bracketsā€ http://hist-analytic.com/Lewisdot.pdf

2 Likes