[Haskell-cafe] String to Double conversion in Haskell

Jefferson Heard jefferson.r.heard at gmail.com
Sun Aug 24 18:13:13 EDT 2008


Because normally, Prelude.read covers this.  Don's link is the most
efficient, but you can also do

(read . ByteString.unpack $ bytestring) :: Double

to get a Double from a printed representation of most numbers.

2008/8/24 Daryoush Mehrtash <dmehrtash at gmail.com>:
> 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 <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]http://sequence.svcs.cs.pdx.edu/node/373
>> >
>>
>> Use the bytstring-lexing library,
>>
>>
>>  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
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>



-- 
I try to take things like a crow; war and chaos don't always ruin a
picnic, they just mean you have to be careful what you swallow.

-- Jessica Edwards


More information about the Haskell-Cafe mailing list