'Why is Data.Text.Lazy needed? Couldn't strict chunks of a lazy structure be made by a compiler optimizer?

I wonder whether a Haskell compiler optimizer couldn't generally split larger lazy data structures into smaller strict pieces to gain more performant programs.

For example, by Data.Text.Lazy we make the same behavior. Strict chunks of Data.Text in larger lazy structures. If this optimization would be possible, could we just use String instead with the same performance and make the code nicer?

Is there any conceptual/theoretical reason, why this optimization can't be made, or it is just practically so hard, nobody implemented it yet? Is it the current issue among GHC developers?



Solution 1:[1]

So my question is, what is Data.Text.Lazy good for, if String structure using the compiler optimizations (if they exist) should behave just like it?

If String behaved just like Data.Text.Lazy.Text, then there would indeed be no point. But it doesn't, and there are no inklings that it might in the near future.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Wagner