[GHC] #5461: Reconfigurable pretty-printing in GHCi

GHC cvs-ghc at haskell.org
Thu Jun 21 12:14:41 CEST 2012


#5461: Reconfigurable pretty-printing in GHCi
---------------------------------+------------------------------------------
    Reporter:  simonpj           |       Owner:  bravit          
        Type:  feature request   |      Status:  patch           
    Priority:  normal            |   Milestone:  7.6.1           
   Component:  Compiler          |     Version:  7.2.1           
    Keywords:                    |          Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown    
  Difficulty:                    |    Testcase:                  
   Blockedby:                    |    Blocking:                  
     Related:                    |  
---------------------------------+------------------------------------------
Changes (by bravit):

  * status:  new => patch


Comment:

 Feature request is implemented in this way:

 1) User can specify flag `-interactive-print=<Module-name.function-name>`
 in command line or set it via `:set` command in ghci. This function's type
 should be of a form `C a => a -> IO ()`, though this isn't checked prior
 to actual call.

 2) We search for this function in currently loaded modules and registered
 packages. Errors, if any, are reported.

 3) The function is invoked after evaluating of given expression.

 For example, user has this special printing function:
 {{{
 module SpecPrinter where
 import System.IO

 sprint a = putStrLn $ show a ++ "!"
 }}}
 Running command:
 {{{
 ghc -e "[1,2,3]" -interactive-print=SpecPrinter.sprint SpecPrinter
 }}}
 gives output
 {{{
 [1,2,3]!
 }}}

 In GHCi:
 {{{
 Prelude> [1,2,3]
 [1,2,3]
 Prelude> :load SpecPrinter
 *SpecPrinter> :set -interactive-print=SpecPrinter.sprint
 *SpecPrinter> [1,2,3]
 [1,2,3]!
 }}}

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



More information about the Glasgow-haskell-bugs mailing list