I have a problem with ASCII in Haskell.
fromEnum :: Char -> Int
toEnum :: Int -> Char
offset :: Int
offset = fromEnum \'A\' - fromEnum \'a\'
toUpper ::
fromEnum
and toEnum
are standart functions
please try this:
offset :: Int
offset = fromEnum 'A' - fromEnum 'a'
toUpper :: Char -> Char
toUpper ch = toEnum (fromEnum ch + offset)
Unless you are doing this as an exercise, you should really use toUpper
from module Data.Char
.
Doing this well requires to check how uppercase is defined in Unicode -- I'd rather rely on the standard library for that :)
Also, watch out because your toUpper
is not idempotent: one might expect that toUpper 'A' == 'A'
, for instance.