This statement is almost true, because every String
(unless it contains surrogate characters!) can be replaced by a lazy Text
, where each chunk contains exactly one Char
. But I assume this is not what you mean?
If the statement was to mean that String
can be replaced by strict Text
then it’s false, you can easily face major performance penalties if you do so.
For instance, tasty
uses String
. Never been an issue.
How exactly [Data.Text.Text]
is better than Data.Text.Lazy.Text
? They are almost isomorphic (chunks of lazy text are guaranteed to be nonempty) and the existing implementation of lazy Text
is indeed built upon the implementation of strict Text
, so I don’t see who is to win and what is to be saved. Mind you that one would still need to wrap [Text]
into a newtype to provide instances.
I remember alternative preludes being all rage around 2016. Pretty much all of them are abandoned or on life support in 2024, causing great pain to projects who embraced them. Alternative preludes do not stand the test of time.
As for text
I would strongly advise against moving the entire package into base
. But we can move data Text
and its instances.
You can define (:+)
as below and use it instead of (:)
:
pattern (:+) :: Char -> Text -> Text
pattern x :+ xs <- (uncons -> Just (x, xs)) where
x :+ xs = cons x xs