[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-26 Thread Christian Maeder
Andy Gimblett schrieb: Hi Christian, [...] It may make sense to use something like readMaybe (which is missing in the Prelude) instead of read to allow the parser to fail more nicely. It seems to be kicking up reasonable errors as it is, e.g.: *Main parse aFloat 2e-h Left (line 1,

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-26 Thread Evan Laforge
real :: Parser String real = do  d - decimal  f - option $ do    p - char '.'    n - many1 digit    return $ p : n Just to throw two bits in here, this is the only style that doesn't require leaning on the space bar and squinting to line things up, doesn't require any fancy editor

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-25 Thread Andy Gimblett
Hi Christian, On 24 Feb 2010, at 13:24, Christian Maeder wrote: I hope you don't mind if I make some style comments to your final version. Not at all - thanks! 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) I'm not

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-25 Thread Neil Brown
Andy Gimblett wrote: 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) I'm not convinced by this; perhaps while editing the code it's useful, but those changes don't happen very often, and when they do, any half-decent

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-24 Thread Christian Maeder
Andy Gimblett schrieb: For the record, here's the final improved version: Hi Andy, I hope you don't mind if I make some style comments to your final version. 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) 2. The t ::

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-24 Thread Ben Millwood
On Wed, Feb 24, 2010 at 1:24 PM, Christian Maeder christian.mae...@dfki.de wrote: 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) You can also break it immediately before do, which I think is sometimes more clear.

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-24 Thread Christian Maeder
Ben Millwood schrieb: On Wed, Feb 24, 2010 at 1:24 PM, Christian Maeder christian.mae...@dfki.de wrote: 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) You can also break it immediately before do, which I think is

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Christian Maeder
Andy Gimblett schrieb: Hi all, Short version: How can I pretty print and parse values of type Double such that those operations are each other's inverse? Maybe you have more luck with show and read (without Parsec.Token). Your example: x = 9.91165677454629 fails because the computation

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett
Short version: How can I pretty print and parse values of type Double such that those operations are each other's inverse? Maybe you have more luck with show and read (without Parsec.Token). Your example: x = 9.91165677454629 fails because the computation performed by the parser 9.0 +

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett
For the record, here's the final improved version: float' :: TokenParser st - GenParser Char st Double float' t = do n - liftCtoS '-' w - many1 digit char '.' f - many1 digit e - option $ do char 'e' n' -