The Data.Char module does what its name suggests: it exports functions that deal with characters. But they’re also helpful when filtering and mapping over strings because they’re just lists of characters
ghci 1> import Data.Char
Here are some of the exported predicates over characters (functions of type Char -> Bool):
Most of the time, we use these to filter out strings.
ghci 2> all isAlphaNum "bobby283" True ghci 3> all isAlphaNum "eddy the fish!" False
The Data.Char also exports a datatype GeneralCategory that’s like Ordering. The Ordering type can have a value of LT, EQ or GT – a sort of enumeration. It describes a few possible results that can arise from comparing two elements.
The GeneralCategory type is also an enumeration. It presents us with a few possible categories that a character can fall into. The main function for getting the general category of a character is generalCategory. Its type is listed below
ghci 4> : t generalCategory generalCategory :: Char → GeneralCategory ghci 5> generalCategory ’ ’ Space ghci 6> generalCategory ’A’ UppercaseLetter ghci 7> generalCategory ’a’ LowercaseLetter ghci 8> generalCategory ’.’ OtherPunctuation ghci 9> generalCategory ’9’ DecimalNumber
toUpper converts a character to an upper-case. Spaces, numbers, and the like remain unchanged.
ghci 10> map toUpper "wow that’s great r2-d2" "WOW THAT’S GREAT R2-D2"
toLower converts a character to a lower-case.
ghci 11> map toLower "WOW THAT’S GREAT R2-D2" "wow that’s great r2-d2"
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.