HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefoundation-0.0.30Haskell2010

Foundation.String.Read

  • 6 values
  • Packagefoundation-0.0.30
  • Exports6
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceString.hs

Try to read a floating number as a Rational

Note that for safety reason, only exponent between -10000 and 10000 is allowed as otherwise DoS/OOM is very likely. if you don't want this behavior, switching to a scientific type (not provided yet) that represent the exponent separately is the advised solution.

valuereadFloatingExact :: String -> ReadFloatingCallback a -> Maybe a
#

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 digits part represented as a single natural number (123.456 is represented as 123456)

  • The number of digits in the fractional part (e.g. 123.456 => 3)

  • The exponent 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 remaining digits if not already end of string

  • Optionally Consume a e or E follow by an optional - and a number