import Char (isDigit)
toHanDigit :: String -> String
toHanDigit = toDigit.zenToHan
toDigit :: String -> String
toDigit [] = []
toDigit (x:xs) = if isDigit x then x:toDigit xs else toDigit xs
zenToHan :: String -> String
zenToHan s = tr "0123456789" "0123456789" s
tr :: String -> String -> String -> String
tr from to = map f
where
f c = case lookup c tbl of
Nothing -> c
Just c' -> c'
tbl = zip from to
> toHanDigit "abc02dd34123ghhgs" --=> "0234123"
import Data.Map
tr :: String -> String -> String -> String
tr from to = Prelude.map f
where
f c = case Data.Map.lookup c charMap of
Nothing -> c
Just c' -> c'
charMap = fromList $ zip from to
han = han0 ++ han1 ++ han2 ++ han3
zen = zen0 ++ zen1 ++ zen2 ++ zen3
han0 =" !\"#$%&'()*+,-./"
zen0 =" !”#$%&’()*+,ー./"
han1 ="0123456789:;<=>?@"
zen1 ="0123456789:;<=>?@"
han2 ="ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
zen2 ="ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_‘"
han3 ="abcdefghijklmnopqrstuvwxyz{|}~"
zen3 ="abcdefghijklmnopqrstuvwxyz{|}〜"
> putStrLn $ tr zen han "ABCDE読んだことが"
--=> ABCDE読んだことが
> putStrLn $ tr han zen ['A'..'Z']
--=> ABCDEFGHIJKLMNOPQRSTUVWXYZ