42 lines
1.4 KiB
Haskell
42 lines
1.4 KiB
Haskell
|
toWord :: Int -> [Char]
|
||
|
toWord = toWord' . show
|
||
|
|
||
|
toWord' :: [Char] -> [Char]
|
||
|
toWord' ('0':[]) = ""
|
||
|
toWord' ('1':[]) = "one"
|
||
|
toWord' ('2':[]) = "two"
|
||
|
toWord' ('3':[]) = "three"
|
||
|
toWord' ('4':[]) = "four"
|
||
|
toWord' ('5':[]) = "five"
|
||
|
toWord' ('6':[]) = "six"
|
||
|
toWord' ('7':[]) = "seven"
|
||
|
toWord' ('8':[]) = "eight"
|
||
|
toWord' ('9':[]) = "nine"
|
||
|
|
||
|
toWord' ('1':'0':[]) = "ten"
|
||
|
toWord' ('1':'1':[]) = "eleven"
|
||
|
toWord' ('1':'2':[]) = "twelve"
|
||
|
toWord' ('1':'3':[]) = "thirteen"
|
||
|
toWord' ('1':'4':[]) = "fourteen"
|
||
|
toWord' ('1':'5':[]) = "fifteen"
|
||
|
toWord' ('1':'6':[]) = "sixteen"
|
||
|
toWord' ('1':'7':[]) = "seventeen"
|
||
|
toWord' ('1':'8':[]) = "eighteen"
|
||
|
toWord' ('1':'9':[]) = "nineteen"
|
||
|
|
||
|
toWord' ('2':c:[]) = "twenty" ++ toWord' (c:[])
|
||
|
toWord' ('3':c:[]) = "thirty" ++ toWord' (c:[])
|
||
|
toWord' ('4':c:[]) = "forty" ++ toWord' (c:[])
|
||
|
toWord' ('5':c:[]) = "fifty" ++ toWord' (c:[])
|
||
|
toWord' ('6':c:[]) = "sixty" ++ toWord' (c:[])
|
||
|
toWord' ('7':c:[]) = "seventy" ++ toWord' (c:[])
|
||
|
toWord' ('8':c:[]) = "eighty" ++ toWord' (c:[])
|
||
|
toWord' ('9':c:[]) = "ninety" ++ toWord' (c:[])
|
||
|
|
||
|
toWord' (h:'0':'0':[]) = (toWord' (h:[])) ++ "hundred"
|
||
|
toWord' (h:'0':s:[]) = (toWord' (h:[])) ++ "hundredand" ++ (toWord' (s:[]))
|
||
|
toWord' (h:d:s:[]) = (toWord' (h:[])) ++ "hundredand" ++ (toWord' (d:s:[]))
|
||
|
|
||
|
toWord' (k:'0':'0':'0':[]) = (toWord' (k:[])) ++ "thousand"
|
||
|
toWord' (k:h:d:s:[]) = (toWord' (k:[])) ++ "thousand" ++ toWord' (h:d:s:[])
|