HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulebase-4.20.2.0Haskell2010

GHC.Unicode

Implementations for the character predicates (isLower, isUpper, etc.) and the conversions (toUpper, toLower). The implementation uses libunicode on Unix systems if that is available.

  • 1 type
  • 23 values
  • Packagebase-4.20.2.0
  • Exports24
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceUnicode.hs
datadata GeneralCategory
#

Unicode General Categories (column 2 of the UnicodeData table) in the order they are listed in the Unicode standard (the Unicode Character Database, in particular).

Examples

Basic usage:

Example1 expression
:t OtherLetterOtherLetter :: GeneralCategory

Eq instance:

Example2 expressions
UppercaseLetter == UppercaseLetterTrueUppercaseLetter == LowercaseLetterFalse

Ord instance:

Example1 expression
NonSpacingMark <= MathSymbolTrue

Enum instance:

Example1 expression
enumFromTo ModifierLetter SpacingCombiningMark[ModifierLetter,OtherLetter,NonSpacingMark,SpacingCombiningMark]

Text.Read.Read instance:

Example2 expressions
read "DashPunctuation" :: GeneralCategoryDashPunctuationread "17" :: GeneralCategory*** Exception: Prelude.read: no parse

Show instance:

Example1 expression
show EnclosingMark"EnclosingMark"

Bounded instance:

Example2 expressions
minBound :: GeneralCategoryUppercaseLettermaxBound :: GeneralCategoryNotAssigned

Ix instance:

Example3 expressions
import GHC.Internal.Data.Ix ( index )index (OtherLetter,Control) FinalQuote12index (OtherLetter,Control) Format*** Exception: Error in array index

Constructors

Instances9Bounded, Enum, Eq, Ord, Read, Show, …

The Unicode general category of the character. This relies on the Enum instance of GeneralCategory, which must remain in the same order as the categories are presented in the Unicode standard.

Examples

Basic usage:

Example7 expressions
generalCategory 'a'LowercaseLettergeneralCategory 'A'UppercaseLettergeneralCategory '0'DecimalNumbergeneralCategory '%'OtherPunctuationgeneralCategory '♥'OtherSymbolgeneralCategory '\31'ControlgeneralCategory ' 'Space
valueisAscii :: Char -> Bool
#

Selects the first 128 characters of the Unicode character set, corresponding to the ASCII character set.

valueisLatin1 :: Char -> Bool
#

Selects the first 256 characters of the Unicode character set, corresponding to the ISO 8859-1 (Latin-1) character set.

valueisControl :: Char -> Bool
#

Selects control characters, which are the non-printing characters of the Latin-1 subset of Unicode.

valueisSpace :: Char -> Bool
#

Returns True for any Unicode space character, and the control characters \t, \n, \r, \f, \v.

valueisUpper :: Char -> Bool
#

Selects upper-case or title-case alphabetic Unicode characters (letters). Title case is used by a small number of letter ligatures like the single-character form of Lj.

Note: this predicate does not work for letter-like characters such as: 'Ⓐ' (U+24B6 circled Latin capital letter A) and 'Ⅳ' (U+2163 Roman numeral four). This is due to selecting only characters with the GeneralCategory UppercaseLetter or TitlecaseLetter.

See isUpperCase for a more intuitive predicate. Note that unlike isUpperCase, isUpper does select title-case characters such as 'Dž' (U+01C5 Latin capital letter d with small letter z with caron) or 'ᾯ' (U+1FAF Greek capital letter omega with dasia and perispomeni and prosgegrammeni).

valueisUpperCase :: Char -> Bool
#

Selects upper-case Unicode letter-like characters.

Note: this predicate selects characters with the Unicode property Uppercase, which include letter-like characters such as: 'Ⓐ' (U+24B6 circled Latin capital letter A) and 'Ⅳ' (U+2163 Roman numeral four).

See isUpper for the legacy predicate. Note that unlike isUpperCase, isUpper does select title-case characters such as 'Dž' (U+01C5 Latin capital letter d with small letter z with caron) or 'ᾯ' (U+1FAF Greek capital letter omega with dasia and perispomeni and prosgegrammeni).

valueisLower :: Char -> Bool
#

Selects lower-case alphabetic Unicode characters (letters).

Note: this predicate does not work for letter-like characters such as: 'ⓐ' (U+24D0 circled Latin small letter a) and 'ⅳ' (U+2173 small Roman numeral four). This is due to selecting only characters with the GeneralCategory LowercaseLetter.

See isLowerCase for a more intuitive predicate.

valueisLowerCase :: Char -> Bool
#

Selects lower-case Unicode letter-like characters.

Note: this predicate selects characters with the Unicode property Lowercase, which includes letter-like characters such as: 'ⓐ' (U+24D0 circled Latin small letter a) and 'ⅳ' (U+2173 small Roman numeral four).

See isLower for the legacy predicate.

valueisAlpha :: Char -> Bool
#

Selects alphabetic Unicode characters (lower-case, upper-case and title-case letters, plus letters of caseless scripts and modifiers letters). This function is equivalent to isLetter.

This function returns True if its argument has one of the following GeneralCategorys, or False otherwise:

These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Letter".

valueisHexDigit :: Char -> Bool
#

Selects ASCII hexadecimal digits, i.e. '0'..'9', 'a'..'f', 'A'..'F'.

valueisAlphaNum :: Char -> Bool
#

Selects alphabetic or numeric Unicode characters.

Note that numeric digits outside the ASCII range, as well as numeric characters which aren't digits, are selected by this function but not by isDigit. Such characters may be part of identifiers but are not used by the printer and reader to represent numbers, e.g., Roman numerals like V, full-width digits like '1' (aka '65297').

This function returns True if its argument has one of the following GeneralCategorys, or False otherwise:

valueisPunctuation :: Char -> Bool
#

Selects Unicode punctuation characters, including various kinds of connectors, brackets and quotes.

This function returns True if its argument has one of the following GeneralCategorys, or False otherwise:

These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Punctuation".

Examples

Basic usage:

Example6 expressions
isPunctuation 'a'FalseisPunctuation '7'FalseisPunctuation '♥'FalseisPunctuation '"'TrueisPunctuation '?'TrueisPunctuation '—'True
valueisSymbol :: Char -> Bool
#

Selects Unicode symbol characters, including mathematical and currency symbols.

This function returns True if its argument has one of the following GeneralCategorys, or False otherwise:

These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Symbol".

Examples

Basic usage:

Example3 expressions
isSymbol 'a'FalseisSymbol '6'FalseisSymbol '='True

The definition of "math symbol" may be a little counter-intuitive depending on one's background:

Example2 expressions
isSymbol '+'TrueisSymbol '-'False
valuetoUpper :: Char -> Char
#

Convert a letter to the corresponding upper-case letter, if any. Any other character is returned unchanged.

valuetoLower :: Char -> Char
#

Convert a letter to the corresponding lower-case letter, if any. Any other character is returned unchanged.

valuetoTitle :: Char -> Char
#

Convert a letter to the corresponding title-case or upper-case letter, if any. (Title case differs from upper case only for a small number of ligature letters.) Any other character is returned unchanged.