漢数字への変換

30分プログラム、その798。数字から漢数字への変換をやってみました。
1以上1億未満の数字にのみ対応してます。

使い方

*Main> kanji 10
十
*Main> kanji 42
四十二
*Main> kanji 12345
一万二千三百四十五

ソースコード

import qualified System.IO.UTF8 as U

right  = ["", "一", "二","三","四","五","六","七","八","九"]
left = ["", "二","三","四","五","六","七","八","九"]
sep p xs ys  = ys ++ [ x ++ p ++ y | x <- xs, y <- ys]

xs = sep "万" (tail ys) ys
    where ys = foldl (\x p -> sep p left x) right ["十","百","千"]

kanji n = U.putStrLn (xs !! n)