[Haskell-cafe] String to Double conversion in Haskell

Don Stewart dons at galois.com
Sun Aug 24 18:12:33 EDT 2008


We wrote a readInt a long time ago, because we needed it. It turns out
that really though, there's a large class of functions for parsing
bytestrings should come with, so I've started adding those to the
bytestring-lexing package.

In hindisight ByteString.readInt should have been in a separate package.

-- Don


dmehrtash:
>    I am curious to understand the logic, the "Haskell Think", here.  Why is
>    it that the byteString only supports conversion to int.
> 
>    daryoush
>    On Sun, Aug 24, 2008 at 2:23 PM, Don Stewart <[1]dons at galois.com> wrote:
> 
>      dmehrtash:
>      >    I am trying to convert a string to a float.  It seems that
>      Data.ByteString
>      >    library only supports readInt.    After some googling I came
>      accross a
>      >    possibloe implementation:
>      [1][2]http://sequence.svcs.cs.pdx.edu/node/373
>      >
> 
>      Use the bytstring-lexing library,
> 
>       
>       [3]http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-lexing
> 
>      Which provides a copying and non-copying lexer for doubles,
> 
>         readDouble       :: ByteString -> Maybe (Double, ByteString)
>         unsafeReadDouble :: ByteString -> Maybe (Double, ByteString)
>      -- Don
> 
> References
> 
>    Visible links
>    1. mailto:dons at galois.com
>    2. http://sequence.svcs.cs.pdx.edu/node/373
>    3. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bytestring-lexing


More information about the Haskell-Cafe mailing list