[GHC] #9015: A documented way to differentiate between statements, declarations, imports, etc.

GHC ghc-devs at haskell.org
Sun Apr 20 19:46:55 UTC 2014


#9015: A documented way to differentiate between statements, declarations,
imports, etc.
-------------------------------------+-------------------------------------
       Reporter:  splinterofchaos    |             Owner:
           Type:  feature request    |            Status:  new
       Priority:  normal             |         Milestone:
      Component:  GHC API            |           Version:  7.8.2
       Keywords:                     |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple   |   Type of failure:  Documentation
     Difficulty:  Moderate (less     |  bug
  than a day)                        |         Test Case:
     Blocked By:                     |          Blocking:
Related Tickets:                     |
-------------------------------------+-------------------------------------
 I'm working on a little REPL and the GHC API seems to supply two functions
 for evaluating one line, without compiling and evaluating into an
 `HValue`, which doesn't seem to have an `Outputable` instace: `runStmt`
 and `runDecls`. As it turns out, I need slightly different code to run on
 declarations verses statements, so this makes sense, but given a random
 string from the user, how can I tell the difference? I don't see anything
 in the documentation about this.

 I took a look at ghci's source
 (https://github.com/ghc/ghc/blob/a6f2c852d49313fa8acea2deb3741ab86c6ef995/ghc/InteractiveUI.hs#L862])
 and it looks like they just peek at the first word of the input, and that
 may be correct and sufficient, but impossible to verify without looking at
 Haskell's grammar. But even if I did verify it, that doesn't make explicit
 the difference between what `runDecls` and `runStmt` will accept.

 For a contrived example, consider if GHC implemented a feature that
 allowed for a new type of decl. It might be enabled by a language
 extension which means that testing whether a string is a statement or
 declaration cannot be done purely as we have to check the dynflags.
 Furthermore, the client may not be aware of the extension and thus send
 the input to `runStmt` instead.

 It would seem to me that requiring the user to manually parse the input
 violates separation of concerns since truly GHC knows best what source GHC
 will accept. The user should not have to examine the input except for if
 they need to modify or interpret it as something other than Haskell source
 code.

 The GHC API should either document an example function for differentiating
 declarations from statements (and even import statements), supply one
 itself, or supply several along the lines of `isDecl, isStmt, isImport ::
 String -> Bool`. This would improve ease-of-use by making client code more
 obvious and correct.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9015>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list