[Haskell-cafe] Parsec : parse either an interger or a double?

Fredrik Karlsson dargosch at gmail.com
Sun Jul 7 14:32:56 CEST 2013


Sorry for answering my own question :

end <- try (float haskelldef)
<|> (fmap fromInteger $ integer haskelldef )

appears to work nicelly. Sorry about that.

/Fredrik


On Sun, Jul 7, 2013 at 1:57 PM, Fredrik Karlsson <dargosch at gmail.com> wrote:

> Dear list,
>
> Sorry for asking you another parsec question. I have  a text file that is
> the output of a C/C++ program, involving time references in double format.
> Now, the program seems to truncate the output if possible, so a file that
> is one second long will produce this file:
>
> File type = "ooTextFile"
> Object class = "TextGrid"
>
> xmin = 0
> xmax = 1
> ....
>
> and a file that is 1.1 seconds long will be this:
>
> File type = "ooTextFile"
> Object class = "TextGrid"
>
> xmin = 0
> xmax = 1.1
> ...
>
> Now, how do I handle this case in parsec?
>
> I have tried this:
>
> start <- try (float haskellDef)
> <|>  fmap ( / 1.0 ) $ integer haskelldef
>
> and similar solutions, but I cant get it to accept the 0.
>
> /Fredrik
>
> --
> "Life is like a trumpet - if you don't put anything into it, you don't get
> anything out of it."
>



-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130707/a43f79aa/attachment.htm>


More information about the Haskell-Cafe mailing list