HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleunicode-data-0.4.0.1Haskell2010

Unicode.Char.Numeric

Numeric character property related functions.

  • 9 values

Predicates

2 declarations
valueisNumeric :: Char -> Bool
#

Selects Unicode character with a numeric value.

Note: a character may have a numeric value but return False with the predicate isNumber, because isNumber only tests GeneralCategory: some CJK characters are OtherLetter and do have a numeric value.

Property
isNumeric c == isJust (numericValue c)
valueisNumber :: Char -> Bool
#

Deprecated. Use Unicode.Char.Numeric.Compat.isNumber instead. This function will be a synonym for isNumeric in a future release. See Unicode.Char.Numeric.Compat for behavior compatible with base:Data.Char.

Selects Unicode numeric characters, including digits from various scripts, Roman numerals, et cetera.

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

Note: a character may have a numeric value (see numericValue) but return False, because isNumber only tests GeneralCategory: some CJK characters are OtherLetter and do have a numeric value. Use isNumeric to cover those cases as well.

Property
isNumber c == Data.Char.isNumber c

Numeric values

2 declarations

Re-export from base

5 declarations
valueisHexDigit :: Char -> Bool
#

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

valuedigitToInt :: Char -> Int
#

Convert a single digit Char to the corresponding Int. This function fails unless its argument satisfies isHexDigit, but recognises both upper- and lower-case hexadecimal digits (that is, '0'..'9', 'a'..'f', 'A'..'F').

Examples

Characters '0' through '9' are converted properly to 0..9:

Example1 expression
map digitToInt ['0'..'9'][0,1,2,3,4,5,6,7,8,9]

Both upper- and lower-case 'A' through 'F' are converted as well, to 10..15.

Example2 expressions
map digitToInt ['a'..'f'][10,11,12,13,14,15]map digitToInt ['A'..'F'][10,11,12,13,14,15]

Anything else throws an exception:

Example2 expressions
digitToInt 'G'*** Exception: Char.digitToInt: not a digit 'G'digitToInt '♥'*** Exception: Char.digitToInt: not a digit '\9829'
valueintToDigit :: Int -> Char
#

Convert an Int in the range 0..15 to the corresponding single digit Char. This function fails on other inputs, and generates lower-case hexadecimal digits.