Proposal: Add a Read instance for Data.Fixed.Fixed

Ian Lynagh igloo at earth.li
Tue Nov 16 17:36:36 EST 2010


Proposal: Add a Read instance for Data.Fixed.Fixed
http://hackage.haskell.org/trac/ghc/ticket/4502

Patch and test in the ticket; the essence is:

readsFixed :: (HasResolution a) => ReadS (Fixed a)
readsFixed = readsSigned
    where readsSigned ('-' : xs) = [ (negate x, rest)
                                   | (x, rest) <- readsUnsigned xs ]
          readsSigned xs = readsUnsigned xs
          readsUnsigned xs = case span isDigit xs of
                             ([], _) -> []
                             (is, xs') ->
                                 let i = fromInteger (read is)
                                 in case xs' of
                                    '.' : xs'' ->
                                        case span isDigit xs'' of
                                        ([], _) -> []
                                        (js, xs''') ->
                                            let j = fromInteger (read js)
                                                l = genericLength js :: Integer
                                            in [(i + (j / (10 ^ l)), xs''')]
                                    _ -> [(i, xs')]

Suggested deadline: 1 Dec 2010.


Thanks
Ian



More information about the Libraries mailing list