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/ 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:

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”

1 Like