Open dschrempf opened 6 years ago
+1 very confusing not having the fastest solution as part of the Text package. Please consider adding or directing readers of documentation in the right direction.
Agree.
I think there is no debate there should be a fast function to convert: Integral a => a -> Text
at least.
Very surprised the fastest ways in the default library are manually through Lazy Builder, then assemble it, then additionally run O(n) toStrict
on it, it is, well, a bit excessive.
There is: text-builder where is decimal :: Integral a => a -> Builder
.
Good if that package would've been upstreamed here.
Is this request under consideration? I was surprised to find that this does not exist yet.
Float-to-string conversion is hard. Once https://github.com/haskell/bytestring/pull/365 lands into bytestring
and UTF8-based text-2.0
is released, the fastest way will be to create a ByteString
and convert it to Text
.
@Bodigrim Currently, the haskell/bytestring#365 has been pulled but, I have recently updated the float to string implementation in bytestring and have greatly improved its performance and added some capabilities. However, I have not made any breaking changes to the interface and integration to text can begin now.
The performance and organization PRs currently submitted
New formatting options
Also, the Ryu algorithm may not print floating point numbers the same as your current implementation since it minimizes the the number of digits printed. I have not looked at the text implementation so this may not be an issue.
Thanks @BebeSparkelSparkel. I'm severely overloaded at the moment, but I'm sure @clyring will review your PRs for bytestring
. Feel free to ping me in a couple of weeks though.
A PR migrating text
to use bytestring
for double-to-string conversion would be welcome.
I think it's time we add
intToText :: Integral a => a -> T.Text
intToText = T.toStrict . B.toLazyText . B.decimal
because this incantation is so arcane that the vast majority of users succumb to T.pack . show
, which is very inefficient.
I'm unsure about the name. It should mention that it's a decimal representation, not hexadecimal. Maybe simply Data.Text.decimal
?..
Hi,
may I suggest adding conversion functions such as
to
Data.Text
because I spent now around two hours in finding a way to convert numbers to Text objects. Maybe there is a better way, in that case it would be nice to have it documented in the main file of the module.Thank you!