[GHC] #9628: Add Annotations to the AST to simplify source to source conversions

GHC ghc-devs at haskell.org
Fri Oct 10 16:36:18 UTC 2014


#9628: Add Annotations to the AST to simplify source to source conversions
-------------------------------------+-------------------------------------
              Reporter:  alanz       |            Owner:  alanz
                  Type:  feature     |           Status:  new
  request                            |        Milestone:
              Priority:  normal      |          Version:  7.9
             Component:  Compiler    |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:              |  Related Tickets:
  None/Unknown                       |
             Test Case:              |
              Blocking:              |
Differential Revisions:  D297        |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Thanks for the wiki page -- extremely helpful.

 I'm concerned about the proliferation of data types. As I read it you
 intend to have a new data type for each constructor of each data type in
 `HsSyn`.  That's a LOT of new data types!  And I bet you'll soon want Eq,
 Ord, Data instances for them as well as Typeable. Indeed you say
 {{{
 data AnnClassDecl = AnnClassDecl
         { aclassdecl_class   :: SrcSpan
         , aclassdecl_mwhere  :: Maybe SrcSpan
         , aclassdecl_mbraces :: Maybe (SrcSpan,SrcSpan) }
             deriving (Eq,Data,Typeable,Show)
 }}}

 I wonder if something simpler and more dynamically-typed might do.
 Suppose you had
 {{{
 lookupApiAnns :: Typeable value => ApiAnns -> SrcSpan -> String -> Maybe
 value
 }}}
 so that `ApiAnns` is really a map from `(SrcSpan, String, TypeRep)` to
 values, where `TypeRep` there is the `TypeRep` of the value.  The `String`
 is the dynamic bit.  Now you could say
 {{{
 processHsClassDecl :: ApiAnns -> LTyClDecl n -> ...
 processHsClassDecl anns (L l (ClassDecl { ..} )) = r
   where
     Just kwd_loc = lookupAPiAnns anns loc "class-keyword" :: Maybe SrcSpan
     Just mb_loc  = lookupApiAnns anns loc "class-mwhere" :: Maybe (Maybe
 SrcSpan)
     ...
 }}}
 OK so you might type those strings in wrong -- but if you do the look up
 will fail.

 I don't want this to sink under the sheer weight of gratuitous
 declarations.

 Oh and you could use the same string in lots of places.  e.g. "where-
 keyword" might be used in a number of constructs.

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


More information about the ghc-tickets mailing list