text
text copied to clipboard
Export `replicateChar`
Could this function be exported from Data.Text
?
what's the benefit? why isn't replicate
+singleton
good enough? Note that we're rather reluctant to increase the API surface of Data.Text
without a very good justification.
If replicate
+singleton
has the same performance characteristics, that's great. replicateChar
just looked like it was accidentally unexported, because it has a properly formatted haddock.
Fwiw, it was intentionally removed from the public API almost a decade ago via c8a85dc34e24e7b3aebc22a782f2957734b5d830 ; so this is clearly no oversight.
Sounds good, thanks!
I wish replicateChar
were still exported.
replicate n (singleton c)
is much less convenient, causing people to write replicate n "c"
, which is much less efficient! (at least in terms of Core)
See https://github.com/quchen/prettyprinter/issues/131 for context.
IMHO this gotcha regarding using overloaded literals for single-character Text
s should at least be pointed out in the documentation.
what's the benefit? why isn't
replicate
+singleton
good enough? Note that we're rather reluctant to increase the API surface ofData.Text
without a very good justification.
Couldn't replicateChar
be moved to Data.Text.Internal
and exported there? This would give a clear indication that it is not part of the officially supported API, but still allow people to use it.
It is frustrating to know about the performance overhead of replicate n "c"
while replicateChar
is sitting there unexported. The current alternatives are either ugly (replicate n (singleton 'c')
) or require adding boilerplate (redefining replicateChar
).
@pedrominicz is there a performance overhead still? Could you demonstrate it with text-2.0.1
?
@Bodigrim the Core for overloadedString
is 20 times bigger than for singletonChar
(compiled with -O2 -ddump-simpl -ddump-to-file
and text-2.0.1
). I haven't looked deep into it, but the size difference doesn't seem like a good sign.
{-# LANGUAGE OverloadedStrings #-}
import Data.Text
import qualified Data.Text as T
overloadedString :: Text
overloadedString = T.replicate 10 "c"
singletonChar :: Text
singletonChar = T.replicate 10 (T.singleton 'c')
@pedrominicz thanks, I see. Is it any better with the latest master
branch?
@Bodigrim just tried the latest master
branch (https://github.com/haskell/text/commit/5558730e76923f2d5d7fbc8783ab1ecc25bfe15d) and the Core for overloadedString
is still massive compared to singletonChar
. I used the same GHC flags as in my previous comment.