Char

Functions for working with characters. Character literals are enclosed in 'a' pair of single quotes.

Characters

type Char

A Char is a single unicode character:

'a'

'0'

'Z'

'?'

'"'

'Σ'

'🙈'

'\t'

'"'

'\''

'🙈' -- '🙈'

Note 1: You cannot use single quotes around multiple characters like in JavaScript. This is how we distinguish String and Char values in syntax.

Note 2: You can use the unicode escapes from \u{0000} to \u{10FFFF} to represent characters by their code point. You can also include the unicode characters directly. Using the escapes can be better if you need one of the many whitespace characters with different widths.

ASCII Letters

isUpper : Char -> Bool

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

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

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

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

Detect digits 0123456789

isDigit '0' == True

isDigit '1'
    == True
    ... isDigit '9'
    == True

isDigit 'a' == False

isDigit 'b' == False

isDigit 'A' == False
isOctDigit : Char -> Bool

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

Detect hexadecimal digits 0123456789abcdefABCDEF

Conversion

toUpper : Char -> Char

Convert to upper case.

toLower : Char -> Char

Convert to lower case.

toLocaleUpper : Char -> Char

Convert to upper case, according to any locale-specific case mappings.

toLocaleLower : Char -> Char

Convert to lower case, according to any locale-specific case mappings.

Unicode Code Points

toCode : Char -> Int

Convert to the corresponding Unicode code point.

toCode 'A' == 65

toCode 'B' == 66

toCode '木' == 0x6728

toCode '𝌆' == 0x0001D306

toCode '😃' == 0x0001F603
fromCode : Int -> Char

Convert a Unicode code point to a character.

fromCode 65 == 'A'

fromCode 66 == 'B'

fromCode 0x6728 == '木'

fromCode 0x0001D306 == '𝌆'

fromCode 0x0001F603 == '😃'

fromCode -1 == '�'

The full range of unicode is from 0 to 0x10FFFF. With numbers outside that range, you get the replacement character.