HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulebytestring-lexing-0.5.0.16Haskell2010

Data.ByteString.Lex.Integral

Functions for parsing and producing Integral values from/to ByteStrings based on the "Char8" encoding. That is, we assume an ASCII-compatible encoding of alphanumeric characters.

Since: 0.3.0

Contents
  1. General combinators
  2. Decimal conversions
  3. Hexadecimal conversions
  4. Octal conversions
Synopsis

General combinators

Decimal conversions

Read an unsigned/non-negative integral value in ASCII decimal format. Returns Nothing if there is no integer at the beginning of the string, otherwise returns Just the integer read and the remainder of the string.

If you are extremely concerned with performance, then it is more performant to use this function at Int or Word and then to call fromIntegral to perform the conversion at the end. However, doing this will make your code succeptible to overflow bugs if the target type is larger than Int.

Hexadecimal conversions

Read a non-negative integral value in ASCII hexadecimal format. Returns Nothing if there is no integer at the beginning of the string, otherwise returns Just the integer read and the remainder of the string.

This function does not recognize the various hexadecimal sigils like "0x", but because there are so many different variants, those are best handled by helper functions which then use this function for the actual numerical parsing. This function recognizes both upper-case, lower-case, and mixed-case hexadecimal.

Convert a bitvector into a lower-case ASCII hexadecimal string. This is helpful for visualizing raw binary data, rather than for parsing as such.

Octal conversions

Read a non-negative integral value in ASCII octal format. Returns Nothing if there is no integer at the beginning of the string, otherwise returns Just the integer read and the remainder of the string.

This function does not recognize the various octal sigils like "0o", but because there are different variants, those are best handled by helper functions which then use this function for the actual numerical parsing.