[GHC] #11529: Show instance of Char should print literals for non-ascii printable charcters
GHC
ghc-devs at haskell.org
Wed Feb 3 11:01:47 UTC 2016
#11529: Show instance of Char should print literals for non-ascii printable
charcters
-------------------------------------+-------------------------------------
Reporter: nushio | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by thomie):
You can put something like this in your `.ghci` file:
{{{
:seti -XScopedTypeVariables
:{
let myShow :: Show a => a -> String
myShow x = go (show x) where
go :: String -> String
go [] = []
go s@(x:xs) = case x of
'\"' -> '\"' : str ++ "\"" ++ go rest
'\'' -> '\'' : char : '\'' : go rest'
_ -> x : go xs
where
(str :: String, rest):_ = reads s
(char :: Char, rest'):_ = reads s
:}
:{
let myPrint :: Show a => a -> IO ()
myPrint = putStrLn . myShow
:}
:set -interactive-print=myPrint
}}}
Example:
{{{
Prelude> [(++"の父"), (++"の母")] <*> ["田中", "山田"]
["田中の父","山田の父","田中の母","山田の母"]
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11529#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list