You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was proposed to add rational decoder in #22 to improve accuracy of decoding Double values. Unfortunately, this decoder also doesn't work. There's 6 years old issue in text library regarding rational decoder:
I was quite surprised to find this issue in text library because I was assuming that rational decoder should solve all problems with decoding Double. But my hedgehog property-based tests fail when I use rational decoder. The Encoder works properly though 👍
- 1.0000000000034547e-2+ 1.0000000000034549e-2
As a dirty and quick solution I'm using Read instance for Double to parse values and it works without any problems 👍 So I propose to add read decoder to sv library and add note to rational and double decoders about their accuracy.
This is the decoder (initially implemented by @vrom911, we're using it for Double and UTCTime at the moment and it works like a charm 😊):
readDecoder::foralla. (Reada, Typeablea) =>Decode'ByteStringa
readDecoder = contents >>==\c ->maybe
(badDecode $ errorMsg c)
pure
(readMaybe @a$ decodeUtf8 c)
whereerrorMsg::ByteString->ByteString
errorMsg c ="Expect '"<> typeName @a<>"' but couldn't parse: "<> c
The text was updated successfully, but these errors were encountered:
Thanks for letting me know about this. I'd like to get something like that into the library. I'd like for the user to be able to make the error on their own, either using the Bytestring or not.
Off the top of my head, something like the following (possibly with more general types)
read :: Read a => Decode' Bytestring a
read' :: Read a => (ByteString -> DecodeError' ByteString) -> Decode' a
I will get around to this eventually. I'd accept a pull request much sooner :) although I wouldn't want TypeApplications like you're using there since I'd like to keep supporting GHC 7.10 for the time being.
It was proposed to add
rational
decoder in #22 to improve accuracy of decodingDouble
values. Unfortunately, this decoder also doesn't work. There's 6 years old issue intext
library regardingrational
decoder:Data.Text.Read.rational
no more accurate thanData.Text.Read.double
haskell/text#34I was quite surprised to find this issue in
text
library because I was assuming thatrational
decoder should solve all problems with decodingDouble
. But myhedgehog
property-based tests fail when I userational
decoder. TheEncoder
works properly though 👍As a dirty and quick solution I'm using
Read
instance forDouble
to parse values and it works without any problems 👍 So I propose to addread
decoder tosv
library and add note torational
anddouble
decoders about their accuracy.This is the decoder (initially implemented by @vrom911, we're using it for
Double
andUTCTime
at the moment and it works like a charm 😊):The text was updated successfully, but these errors were encountered: