This is the correct behavior. The number is 0.9not represented in the form Double, and not in Haskell, C or Java. This is due to the fact that Doublethey Floatuse base 2: they can accurately represent only a certain subset of binary fractions.
, Numeric readFloat. ( ReadS), . :
import Numeric
myReadFloat :: String -> Rational -- type signature is necessary here
myReadFloat str =
case readFloat str of
((n, []):_) -> n
_ -> error "Invalid number"
, :
> myReadFloat "0.9"
9 % 10