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

Predicates over characters :

Here are some of the exported predicates over characters (functions of type Char -> Bool):

  • isSpace isSpace checks whether a character is a white-space character; that includes spaces, tab characters, newlines etc.
  • isLower isLower checks whether a character is a lower-case character
  • isUpper isUpper checks whether a character is an upper-case character
  • isAlpha isAlpha checks whether a character is a letter
  • isAlphaNum isAlphaNum checks whether a character is a letter or a number
  • isDigit isDigit checks whether a character is a digit
  • isLetter isLetter checks whether a character is a letter
  • isNumber isNumber checks whether a character is numeric
  • isPunctuation isPunctuation checks whether a character is punctuation
  • isSymbol isSymbol checks whether a character is a fancy mathematical or currency symbol

Most of the time, we use these to filter out strings.

ghci 2> all isAlphaNum "bobby283"

ghci 3> all isAlphaNum "eddy the fish!"


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 ’ ’

ghci 6> generalCategory ’A’

ghci 7> generalCategory ’a’

ghci 8> generalCategory ’.’

ghci 9> generalCategory ’9’

toUpper, toLower :

toUpper converts a character to upper-case. Spaces, numbers and the like remain unchanged.

ghci 10> map toUpper "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"

About Author

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Protractor Online Training : I am starting online training course for Protractor with Typescript from 15th November 2018.

You can attend first 3 classes for free, the total course fee is INR 10,000

The course time would be 8.00 PM(IST) for the first three classes

The course time would be 8.00 PM(IST) for the first three classes

If you are interested to learn then you can join the course by sending email to

or Register below

Join My Facebook Group
Join Group