[GHC] #8822: Allow -- ^ Haddock syntax on record constructors

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Parser) | Version: 7.9 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | -------------------------------------+------------------------------------- Original ticket is on Haddock Trac [http://trac.haskell.org/haddock/ticket/144 here] which I'm opening here as it requires lexer/parser changes. The idea is that given something like {{{ -- | A tree with labeled internal nodes data Tree = Empty -- ^ Leaf | Branch -- ^ Internal node { label :: a -- ^ Node label , subtrees :: [Tree] -- ^ List of subtrees } }}} we'd like it to parse as the user would expect instead of failing. We're currently forced to do something like {{{ -- | A tree with labeled internal nodes data Tree = Empty -- ^ Leaf | -- | Internal node Branch { label :: a -- ^ Node label , subtrees :: [Tree] -- ^ List of subtrees } }}} which is quite ugly. I can't think of a reason why the first form wouldn't be allowed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Parser) | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: Unknown/Multiple | Difficulty: Moderate (less Type of failure: None/Unknown | than a day) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by goldfire): * difficulty: Unknown => Moderate (less than a day) Comment: I took a look at this, and it requires more happy-fu than I've got at the moment. Suppose that we implemented parsing as requested, Then, the problem is that the parser gets mightily confused when it sees {{{ data Foo = Bar -- ^ urk }}} What should it expect next? A `|` and another constructor? Or a `{` and a list of fields? Given the current way constructors are parsed (as ''types'', to allow the possibility of infix constructors), there's not an easy way to restructure things to answer this question (that I can see). On the plus side, I think that solving this problem would make it easier to implement something I've wanted: the ability to annotate individual constructor arguments, like so: {{{ data Foo = Bar Int -- ^ urk Double -- ^ blah }}} which would currently be difficult to parse. If someone wants to restructure this section of the parser, please go for it! :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: (Parser) | Architecture: Unknown/Multiple Resolution: | Difficulty: Moderate (less Operating System: | than a day) Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #9770 None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * related: => #9770 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9770, #12050 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * related: #9770 => #9770, #12050 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9770, #12050 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): Found an example very close to @goldfire's example above: {{{ data Command = -- | Run a job. Run String -- ^ Name. Bool -- ^ Fast. [String] -- ^ Run arguments. | -- | Stop a job. Stop Int -- ^ Job number. }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9770, #12050 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by harpocrates): I have a patch that implements both the initial idea and the the suggestion in comment:4. I'll link to it shortly. The only unpleasantness here is that we probably want to maintain backwards compatibility. For that, I decided to lift doc comments on the last field of the constructor to the constructor, provided there are no other doc comments either on the constructor or any of the other fields. This ensures that existing docs will all still parse the same way. {{{ data Foo = Bar Int String -- ^ doc on `Bar` constructor | Baz -- ^ doc on the `Baz` constructor Int -- ^ doc on the `Int` field of `Baz` String -- ^ doc on the `String` field of `Baz` | Int :+ String -- ^ doc on the `:+` constructor | Int -- ^ doc on the `Int` field of the `:*` constructor :* -- ^ doc on the `:*` constructor String -- ^ doc on the `String` field of the `:*` constructor | Boo { x :: () } -- ^ doc on the `Boo` record constructor | Boa -- ^ doc on the `Boa` record constructor { y :: () } }}} The patch also adds support for doc comments on GADT constructor arguments. {{{ data Foo where Foo :: Int -- ^ `Int` field of `Foo` -> String -- ^ `String` field of `Foo` -> Foo }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9770, #12050 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by harpocrates): Here is the patch I mentioned in comment:5. https://phabricator.haskell.org/D4094 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9770, #12050 | Differential Rev(s): Wiki Page: | https://phabricator.haskell.org/D4094 -------------------------------------+------------------------------------- Changes (by harpocrates): * differential: => https://phabricator.haskell.org/D4094 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8822: Allow -- ^ Haddock syntax on record constructors -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Parser) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9770, #12050 | Differential Rev(s): Wiki Page: | https://phabricator.haskell.org/D4094 -------------------------------------+------------------------------------- Changes (by harpocrates): * status: new => closed * resolution: => fixed Comment: Fixed in GHC 8.6. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8822#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC