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 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 lower-case.
ghci 11> map toLower "WOW THAT’S GREAT R2-D2" "wow that’s great r2-d2"
Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know.
Knowledge is the only thing that doubles when you spend it.
I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation