foundation-0.0.7: Alternative prelude with batteries and no dependencies

Safe HaskellNone
LanguageHaskell2010

Foundation.String.Read

Synopsis

Documentation

readInteger :: String -> Maybe Integer Source #

Read an Integer from a String

Consume an optional minus sign and many digits until end of string.

readNatural :: String -> Maybe Natural Source #

Read a Natural from a String

Consume many digits until end of string.

readDouble :: String -> Maybe Double Source #

Try to read a Double

readFloatingExact :: String -> ReadFloatingCallback a -> Maybe a Source #

Read an Floating like number of the form:

-
numbers [ . numbers ] [ ( e | E ) [ - ] number ]

Call a function with:

  • A boolean representing if the number is negative
  • The leading integral part
  • The floating part (number of digits after fractional part, and number) if any
  • The exponant if any

The code is structured as a simple state machine that:

  • Optionally Consume a - sign
  • Consume number for the integral part
  • Optionally
  • Consume .
  • Consume leading zeros explicitely to gather scale of the fractional part
  • Consume remaining digits if not already end of string
  • Optionally Consume a e or E follow by an optional - and a number