I am attempting to write a code to take in an integer and output that integer in words. Ex: if the input is 4321 the output is four thousand three hundred twenty one. For this, I would first like to break the input into it's individual digits. ex input 4321 would become an array of [4,3,2,1].
My current code
newtype wordInt = WI Int
instance Show WordInt where
show (WI x) | x>= 0 = helper x
| x < 0 = helper -x
helper 0 = [0]
helper x = x `mod` 10 : helper (x `div` 10)
At the moment, I think i'm getting a type error. Please note that this needs to be able to hand both positive and negative numbers. Also, if you can think of an efficient way to do the conversion i'm looking for, it would be much appreciated.
'instead of`ondiv), but only goes halfway to your goal; i.e. it breaks the input into its individual digits but does not translate them into words. That is why the compiler is complaining.divnot 'div'.