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

#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...]) 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

#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 Resolution: | 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: -------------------------------------+------------------------------------- Comment (by simonpj): I agree. Would you like to submit a patch, implementing (and documenting) the functions you describe; and then calling them from the (ill-named) `InteractiveUI.runStmt`? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9015#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 Resolution: | 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: -------------------------------------+------------------------------------- Comment (by splinterofchaos): Tentatively, I could, although I wan't sure of the best policy. Perhaps later today, if I have some time but otherwise tomorrow, I might do so. Since GHCi's solution seems to work, I'll just factor it into `InteractiveUI` or a submodule, if more appropriate. Although, on second thought, it would seem more consistent with the current API if instead of predicate functions, I wrote one returning an ADT constructed with something like `AStmt`, `AnImport`, or `ADecl`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9015#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 Resolution: | 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: -------------------------------------+------------------------------------- Comment (by splinterofchaos): On second thought, my computer bricked and I lost my internet connection. Might be quite a while. If someone else could pick this up, I'd appreciate it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9015#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9015: A documented way to differentiate between statements, declarations, imports, etc. -------------------------------------+------------------------------------- Reporter: splinterofchaos | Owner: roshats Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by roshats): * owner: => roshats -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9015#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9015: A documented way to differentiate between statements, declarations, imports, etc. -------------------------------------+------------------------------------- Reporter: splinterofchaos | Owner: roshats Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: GHC API | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: ghc-api/T9015 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1518 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * testcase: => ghc-api/T9015 * differential: => Phab:D1518 * milestone: => 8.0.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9015#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9015: A documented way to differentiate between statements, declarations,
imports, etc.
-------------------------------------+-------------------------------------
Reporter: splinterofchaos | Owner: roshats
Type: feature request | Status: new
Priority: normal | Milestone: 8.0.1
Component: GHC API | Version: 7.8.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Documentation | Unknown/Multiple
bug | Test Case: ghc-api/T9015
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1518
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#9015: A documented way to differentiate between statements, declarations, imports, etc. -------------------------------------+------------------------------------- Reporter: splinterofchaos | Owner: roshats Type: feature request | Status: closed Priority: normal | Milestone: 8.0.1 Component: GHC API | Version: 7.8.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: ghc-api/T9015 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1518 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9015#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC