| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Char
Description
Functions for working with characters. Character literals are enclosed in 'a' pair of single quotes.
Since we don't have a browser and we don't have a default locale, functions
like toLocaleUpper and toLocaleUpper are not supported. If you need
something like that you can check out the 'text-icu' package which provides
functions like toUpper :: LocaleName -> Text -> Text.
Characters
The character type Char represents Unicode codespace
and its elements are code points as in definitions
D9 and D10 of the Unicode Standard.
Character literals in Haskell are single-quoted: 'Q', 'Я' or 'Ω'.
To represent a single quote itself use '\'', and to represent a backslash
use '\\'. The full grammar can be found in the section 2.6 of the
Haskell 2010 Language Report.
To specify a character by its code point one can use decimal, hexadecimal
or octal notation: '\65', '\x41' and '\o101' are all alternative forms
of 'A'. The largest code point is '\x10ffff'.
There is a special escape syntax for ASCII control characters:
| Escape | Alternatives | Meaning |
|---|---|---|
'\NUL' | '\0' | null character |
'\SOH' | '\1' | start of heading |
'\STX' | '\2' | start of text |
'\ETX' | '\3' | end of text |
'\EOT' | '\4' | end of transmission |
'\ENQ' | '\5' | enquiry |
'\ACK' | '\6' | acknowledge |
'\BEL' | '\7', '\a' | bell (alert) |
'\BS' | '\8', '\b' | backspace |
'\HT' | '\9', '\t' | horizontal tab |
'\LF' | '\10', '\n' | line feed (new line) |
'\VT' | '\11', '\v' | vertical tab |
'\FF' | '\12', '\f' | form feed |
'\CR' | '\13', '\r' | carriage return |
'\SO' | '\14' | shift out |
'\SI' | '\15' | shift in |
'\DLE' | '\16' | data link escape |
'\DC1' | '\17' | device control 1 |
'\DC2' | '\18' | device control 2 |
'\DC3' | '\19' | device control 3 |
'\DC4' | '\20' | device control 4 |
'\NAK' | '\21' | negative acknowledge |
'\SYN' | '\22' | synchronous idle |
'\ETB' | '\23' | end of transmission block |
'\CAN' | '\24' | cancel |
'\EM' | '\25' | end of medium |
'\SUB' | '\26' | substitute |
'\ESC' | '\27' | escape |
'\FS' | '\28' | file separator |
'\GS' | '\29' | group separator |
'\RS' | '\30' | record separator |
'\US' | '\31' | unit separator |
'\SP' | '\32', ' ' | space |
'\DEL' | '\127' | delete |
Instances
ASCII Letters
isUpper :: Char -> Bool Source #
Detect upper case ASCII characters.
isUpper 'A' == True isUpper 'B' == True ... isUpper 'Z' == True
isUpper '0' == False isUpper 'a' == False isUpper '-' == False isUpper 'Σ' == False
isLower :: Char -> Bool Source #
Detect lower case ASCII characters.
isLower 'a' == True isLower 'b' == True ... isLower 'z' == True
isLower '0' == False isLower 'A' == False isLower '-' == False isLower 'π' == False
isAlpha :: Char -> Bool Source #
Detect upper case and lower case ASCII characters.
isAlpha 'a' == True isAlpha 'b' == True isAlpha 'E' == True isAlpha 'Y' == True
isAlpha '0' == False isAlpha '-' == False isAlpha 'π' == False
isAlphaNum :: Char -> Bool Source #
Detect upper case and lower case ASCII characters.
isAlphaNum 'a' == True isAlphaNum 'b' == True isAlphaNum 'E' == True isAlphaNum 'Y' == True isAlphaNum '0' == True isAlphaNum '7' == True
isAlphaNum '-' == False isAlphaNum 'π' == False
Digits
isDigit :: Char -> Bool Source #
Detect digits 0123456789
isDigit '0' == True isDigit '1' == True ... isDigit '9' == True
isDigit 'a' == False isDigit 'b' == False isDigit 'A' == False
isOctDigit :: Char -> Bool Source #
Detect octal digits 01234567
isOctDigit '0' == True isOctDigit '1' == True ... isOctDigit '7' == True
isOctDigit '8' == False isOctDigit 'a' == False isOctDigit 'A' == False
isHexDigit :: Char -> Bool Source #
Detect hexadecimal digits 0123456789abcdefABCDEF
Conversion
Unicode Code Points
toCode :: Char -> Int Source #
Convert to the corresponding Unicode code point.
toCode 'A' == 65 toCode 'B' == 66 toCode '木' == 26408 toCode '𝌆' == 0x1D306 toCode '😃' == 0x1F603
fromCode :: Int -> Char Source #
Convert a Unicode code point to a character.
fromCode 65 == 'A' fromCode 66 == 'B' fromCode 0x6728 == '\26408' -- '木' fromCode 0x1D306 == '\119558' -- '𝌆' fromCode 0x1F603 == '\128515' -- '😃' fromCode (-1) == '\65533' -- '�'
The full range of unicode is from 0 to 0x10FFFF. With numbers outside that
range, you get the replacement character#Replacement_character).