[Haskell-cafe] Can we improve Show instance for non-ascii charcters?

Travis Cardwell travis.cardwell at extellisys.com
Wed Feb 3 13:07:26 UTC 2016


On 02/03/2016 10:37 AM, Takayuki Muranushi wrote:
> I think one of the solution is to  import and call u_iswprint from
> GHC.Show, too,
> but I don't know it's against any design choices.

+1 for only escaping non-printable characters.

> Yesterday, I had a chance to teach Haskell (in Japanese,) and I had to
> use English in some of the most exciting examples, like the
> Applicative List example above. I would heartedly like to see GHC
> improve in these directions, so that we can make more happy learning
> materials on Haskell.

As a workaround, perhaps you can avoid using print/show with core data
structures.  Using your applicative example:

> mapM_ putStrLn $ [(++"の父"), (++"の母")] <*> ["田中", "山田"]
田中の父
山田の父
田中の母
山田の母

For other data structures, you can write your own Show instance:

data Name = Name String String

instance Show Name where
  show (Name family given) = family ++ given

> print $ Person "山田" "太郎"
山田太郎

Travis


More information about the Haskell-Cafe mailing list