[GHC] #11028: Refactor ConDecl

GHC ghc-devs at haskell.org
Mon Dec 7 12:10:08 UTC 2015


#11028: Refactor ConDecl
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:  alanz
            Type:  bug               |               Status:  patch
        Priority:  normal            |            Milestone:  8.0.1
       Component:  Compiler          |              Version:  7.10.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11155            |  Differential Rev(s):  Phab:D1558
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Ben Gamari <ben@…>):

 In [changeset:"51a5e68db887adb3565ff2f077267e2b513be562/ghc"
 51a5e68d/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="51a5e68db887adb3565ff2f077267e2b513be562"
 Refactor ConDecl

 The ConDecl type in HsDecls is an uneasy compromise. For the most part,
 HsSyn directly reflects the syntax written by the programmer; and that
 gives just the right "pegs" on which to hang Alan's API annotations. But
 ConDecl doesn't properly reflect the syntax of Haskell-98 and GADT-style
 data type declarations.

 To be concrete, here's a draft new data type

 ```lang=hs
 data ConDecl name
   | ConDeclGADT
       { con_names   :: [Located name]
       , con_type    :: LHsSigType name  -- The type after the ‘::’
       , con_doc     :: Maybe LHsDocString }

   | ConDeclH98
       { con_name    :: Located name

       , con_qvars     :: Maybe (LHsQTyVars name)
         -- User-written forall (if any), and its implicit
         -- kind variables
         -- Non-Nothing needs -XExistentialQuantification

       , con_cxt       :: Maybe (LHsContext name)
         -- ^ User-written context (if any)

       , con_details   :: HsConDeclDetails name
           -- ^ Arguments

       , con_doc       :: Maybe LHsDocString
           -- ^ A possible Haddock comment.
       } deriving (Typeable)
 ```

 Note that

     For GADTs, just keep a type. That's what the user writes.
     NB:HsType can represent records on the LHS of an arrow:

       { x:Int,y:Bool} -> T

     con_qvars and con_cxt are both Maybe because they are both
     optional (the forall and the context of an existential data type

     For ConDeclGADT the type variables of the data type do not scope
     over the con_type; whereas for ConDeclH98 they do scope over con_cxt
     and con_details.

 Updates haddock submodule.

 Test Plan: ./validate

 Reviewers: simonpj, erikd, hvr, goldfire, austin, bgamari

 Subscribers: erikd, goldfire, thomie, mpickering

 Differential Revision: https://phabricator.haskell.org/D1558

 GHC Trac Issues: #11028
 }}}

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


More information about the ghc-tickets mailing list