[Haskell-cafe] Parsec float

Malcolm Wallace malcolm.wallace at cs.york.ac.uk
Thu May 28 17:56:52 EDT 2009

>> is there any reason why float parses only positive numbers?

It is usual in parsing libraries to separate the recognition of a  
leading sign from recognition of the number itself: the sign-only  
parser can be reused in many contexts,  e.g. in the Haskell'98 Numeric  
library, there is

  readSigned :: Real a => ReadS a -> ReadS a

which takes a secondary parser as its argument.  You can instantiate  
that argument to any of

  readDec   :: Num a => ReadS a
  readHex   :: Num a => ReadS a
  readFloat :: Num a => ReadS a

etc.  I do not know if the equivalent of "readSigned" exists in  
Parsec, but it in polyparse's Text.Parse module, it is called  
"parseSigned", rather unsurprisingly.


More information about the Haskell-Cafe mailing list