[Haskell-cafe] String to Double conversion in Haskell

Daryoush Mehrtash dmehrtash at gmail.com
Tue Aug 26 13:27:35 EDT 2008


Bjorn,
I am initializing a list from a file.  I am reading the lines from the file,
splitting them into bytestring and then converting them to float.  Should I
be using String  -> Float or ByteString -> Float?

thanks
Daryoush

On Tue, Aug 26, 2008 at 6:01 AM, Bjorn Bringert <bjorn at bringert.net> wrote:

> 2008/8/24 Daryoush Mehrtash <dmehrtash at gmail.com>:
> > 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: http://sequence.svcs.cs.pdx.edu/node/373
> >
> > My questions are:
> >
> > a) is there a standard library implementation of string -> Double and
> float?
> > b) Why is it that the ByteString only supports readInt? Is there a reason
> > for it?
>
> Hi Daryoush,
>
> are you really looking for ByteString -> Float conversion, or just
> plain String -> Float? The latter is really simple, the function is
> called 'read' and is available in the Prelude:
>
> $ ghci
> GHCi, version 6.8.3: http://www.haskell.org/ghc/  :? for help
> Loading package base ... linking ... done.
> Prelude> read "3.14" :: Float
> 3.14
>
> /Bjorn
>

/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080826/8cf6ef51/attachment.htm


More information about the Haskell-Cafe mailing list