Haskell: Int to Char

Viewed 22020

I am using the function fromEnum to convert a character to its corresponding ASCII Int. For example:

fromEnum 'A'

returns 65.

Now, assuming I had a function that did:

(fromEnum 'A')+1

And then wanted to convert the returned value (66) to a Char which would be 'B'. What is the best way of doing so?

Thanks!

3 Answers
-- Here is my code ex: intToChar 123 // "123"
intToChar :: Integer -> String
intToChar x 
    | x == 0 = ['0']
    | x == 1 = ['1']
    | x == 2 = ['2']
    | x == 3 = ['3']
    | x == 4 = ['4']
    | x == 5 = ['5']
    | x == 6 = ['6']
    | x == 7 = ['7']
    | x == 8 = ['8']
    | x == 9 = ['9']
    | x > 9 = (intToChar (x `div` 10)  ++ intToChar (mod x 10 ) )
Related