Opened 20 months ago

Last modified 11 months ago

#8822 new feature request

Allow -- ^ Haddock syntax on record constructors

Reported by: Fuuzetsu Owned by:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 7.9
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #9770 Differential Rev(s):


Original ticket is on Haddock Trac 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
    { 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.

Change History (2)

comment:1 Changed 20 months ago by goldfire

  • difficulty changed from Unknown to Moderate (less than a day)

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! :)

comment:2 Changed 11 months ago by thomie

Note: See TracTickets for help on using tickets.