simple Haskell help needed on #19746

Richard Eisenberg rae at richarde.dev
Wed Apr 28 02:12:49 UTC 2021



> On Apr 27, 2021, at 3:32 PM, Sebastian Graf <sgraf1337 at gmail.com> wrote:
> 
> Hi Richard,
> 
> Maybe I lack a bit of context, but I don't see why you wouldn't choose (3).
> Extending the lexer/parser will yield a declarative specification of what exactly constitutes a GHC_OPTIONS pragma (albeit in a language that isn't Haskell) and should be more efficient than `reads`, even if you fix it to scale linearly. Plus, it seems that's what we do for other pragmas such as RULE already.

(3) is tempting indeed. There are two problems:

A. The code that parses strings isn't actually declarative. See https://gitlab.haskell.org/ghc/ghc/-/blob/d2399a46a01a6e46c831c19e797e656a0b8ca16d/compiler/GHC/Parser/Lexer.x#L1965. In particular note the comment: "This stuff is horrible. I hates it." Evidently written by Simon M in 2003 with the introduction of alex.

B. We need this code outside the lexer, to deal with e.g. :set in GHCi.

> On Apr 27, 2021, at 4:28 PM, Iavor Diatchki <iavor.diatchki at gmail.com> wrote:
> 
> ... gather ...

Aha! That was the magic incantation I needed but did not have. Many thanks, Iavor.

The curious can see https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5509/diffs?commit_id=a560fcbbc7d4e37c4909385c55839f793b570e68#c1078a9741c11d1e15d4c678b107092790295bb3_308_317 for the final result.

Thanks!
Richard


More information about the ghc-devs mailing list