[GHC] #1966: Incorrect Outputable instance for InstDecl

GHC trac at galois.com
Sun Dec 9 02:57:18 EST 2007


#1966: Incorrect Outputable instance for InstDecl
----------------------------+-----------------------------------------------
    Reporter:  guest        |       Owner:          
        Type:  bug          |      Status:  new     
    Priority:  normal       |   Milestone:          
   Component:  Compiler     |     Version:  6.9     
    Severity:  normal       |    Keywords:          
  Difficulty:  Easy (1 hr)  |    Testcase:          
Architecture:  Multiple     |          Os:  Multiple
----------------------------+-----------------------------------------------
 The pretty-printer produces trash output for instance declarations.  This
 is how the Outputable instance is defined in compiler/hsSyn/HsDecls.lhs:

 {{{
 instance (OutputableBndr name) => Outputable (InstDecl name) where

     ppr (InstDecl inst_ty binds uprags ats)
       = vcat [hsep [ptext SLIT("instance"), ppr inst_ty, ptext
 SLIT("where")],
               nest 4 (ppr ats),
               nest 4 (ppr uprags),
               nest 4 (pprLHsBinds binds) ]
 }}}

 Notice that 'ats' and 'uprags' are lists, so they are being printed as
 such, i.e., with braces and commas.  This produces output that looks like
 this:

 {{{
 instance Monad Maybe where
     []
     []
     return = Just
     fail _ = Nothing
     ...
 }}}

 The correct (I think) definition is this:

 {{{
 instance (OutputableBndr name) => Outputable (InstDecl name) where
     ppr (InstDecl inst_ty binds uprags ats)
       = vcat ([hsep [ptext SLIT("instance"), ppr inst_ty, ptext
 SLIT("where")]] ++
               [ nest 4 (ppr at) | at <- ats ] ++
               [ nest 4 (ppr uprag) | uprag <- uprags ] ++
               [ nest 4 (pprLHsBinds binds) ])
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1966>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list