I've written this code in Haskell to convert a number into its written form. It feels ok but at the same time I feel like it can probably be improved on a lot. I would appreciate help in improving it.
nums :: Int -> String
nums x = case x of
0 -> "zero"
1 -> "one"
2 -> "two"
3 -> "three"
4 -> "four"
5 -> "five"
6 -> "six"
7 -> "seven"
8 -> "eight"
9 -> "nine"
10 -> "ten"
11 -> "eleven"
12 -> "twelve"
13 -> "thirteen"
14 -> "fourteen"
15 -> "fifteen"
16 -> "sixteen"
17 -> "seventeen"
18 -> "eighteen"
19 -> "nineteen"
20 -> "twenty"
30 -> "thirty"
40 -> "forty"
50 -> "fifty"
60 -> "sixty"
70 -> "seventy"
80 -> "eighty"
90 -> "ninety"
100 -> "hundred"
_ -> ""
bigNums :: Int -> String
bigNums x =
case x of
1 -> "thousand"
2 -> "million"
3 -> "billion"
4 -> "trillion"
5 -> "quadrillion"
6 -> "quintillion"
7 -> "sextillion"
8 -> "septillion"
9 -> "octillion"
10 -> "nonillion"
isEmpty :: String -> Bool
isEmpty "" = True
isEmpty s = False
numToEnglish :: String -> Int -> String
numToEnglish start num
| len > 3 =
let exponent = ((len-1) `div` 3) * 3
powerNum = bigNums (exponent `div` 3)
in
if powerNum == ""
then ""
else
let numHead = read $ take (len-exponent) stringNum
numTail = read $ drop (len-exponent) stringNum
numStart = numToEnglish "" numHead ++ " " ++ powerNum
in startSpace ++ numToEnglish numStart numTail
| len == 3 = numToEnglish (startSpace ++ nums firstNum ++ " " ++ nums 100) intTail
| len == 2 =
let tens = nums (firstNum * 10)
includeDash = if not $ isEmpty tens then "-" else ""
in
if firstNum == 1
then startSpace ++ nums num
else
if intTail == 0
then startSpace ++ tens
else startSpace ++ tens ++ includeDash ++ nums intTail
| len == 1 =
if start == ""
then numHead
else if firstNum == 0
then start
else start ++ " " ++ numHead
| otherwise = ""
where
stringNum = show num
len = length stringNum
firstNum = read [head stringNum] :: Int
numHead = if firstNum > 1 || isEmpty start then nums firstNum else ""
intTail = read (drop 1 stringNum) :: Int
startSpace = if isEmpty start then start else start ++ " "
convert :: Int -> String
convert = numToEnglish ""