Design the function which should print a single digit number as English text, or "unknown"
if it's out of the range 0
-9
. The function takes in an Int
and outputs a String
.
Please provide function declaration. You may use a list of strings for your outputs.
This is what I have come up with. Please let me know if anything is wrong with the code, as I am trying to properly learn Haskell coding.
main = do
i<-getLine
let x = (read i :: Int)
print(readDigit x)
readDigit :: Int -> String
readDigit x
| x > 9 || x < 0 = "unknown"
| otherwise = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] !! x