`Data.Text` vs `Data.Vector.Unboxed Char`

Viewed 745

Is there any difference in how Data.Text and Data.Vector.Unboxed Char work internally? Why would I choose one over the other?

I always thought it was cool that Haskell defines String as [Char]. Is there a reason that something analagous wasn't done for Text and Vector Char?

There certainly would be an advantage to making them the same.... Text-y and Vector-y tools could be written to be used in both camps. Imagine Ropes of Ints, or Regexes on strings of poker cards.

Of course, I understand that there were probably historical reasons and I understand that most current libraries use Data.Text, not Vector Char, so there are many practical reasons to favor one over the other. But I am more interested in learning about the abstract qualities, not the current state that we happen to be in.... If the whole thing were rewritten tomorrow, would it be better to unify the two?

Edit, with more info-

To put stuff into perspective-

  1. According to this page, http://www.haskell.org/haskellwiki/GHC/Memory_Footprint, GHC uses 16 bytes for each Char in your program!

  2. Data.Text is not O(1) index'able, it is O(n).

  3. Ropes (binary trees wrapped around text) can also hold strings.... They have better complexity for index/insert/delete, although depending on the number of nodes and balance of the tree, index could be close to that of Text.

This is my takeaway from this-

  1. Text and Vector Char are different internally....

  2. Use String if you don't care about performance.

  3. If performance is important, default to using Text.

  4. If fast indexing of chars is necessary, and you don't mind a lot of memory overhead (up to 16x), use Vector Char.

  5. If you want to insert/delete a lot of data, use Ropes.

2 Answers
Related