Personally, I use ByteStrings for binary data, and Text for textual data.<div><br></div><div>There are a bunch of APIs which use ByteStrings when Text might be a better choice because when they were designed the only choices were ByteString and String. </div>
<div><br></div><div>In some cases, it could be sensible to design a low-level API around ByteString, and build a Text API on top of that. For example, in a SQL database, you may need communicate with the database via utf-8 encoded binary data. So, the low-level binding would use ByteString. But, when you are actually constructing the queries, you probably want to use Text most of the time. The OverloadedStrings instance for ByteString only supports ascii and just truncates utf-8 values resulting in invalid data. But, for Text it does the right thing.</div>
<div><br></div><div>In general, relying on developers to correctly remember and encode the ByteStrings is a poor idea. Generally, when you use Text, the developer doesn&#39;t have to think at all, and the encodings just work. Yay for types!</div>
<div><br></div><div>The only argument for working with ByteStrings everywhere is that it might be faster since you don&#39;t have to do the ByteString &lt;-&gt; Text conversion. But I don&#39;t think there is any data to show that that conversion time is significant. At the very least, it would be sensible to use a newtype wrapper like, newtype UTF8 = UTF8 { toByteString :: ByteString }, to ensure that you get at least some type checking. I am pretty sure this wrapper exists somewhere already.</div>
<div><br></div><div>- jeremy<br><br><div class="gmail_quote">On Sun, Aug 12, 2012 at 1:18 PM, Janne Hellsten <span dir="ltr">&lt;<a href="mailto:jjhellst@gmail.com" target="_blank">jjhellst@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">While working on <a href="https://github.com/nurpax/sqlite-simple" target="_blank">https://github.com/nurpax/sqlite-simple</a> there have<br>

been occasions when I&#39;ve tried to decide whether to use ByteStrings or<br>
Text strings.<br>
<br>
I note that postgresql-simple and mysql-simple use ByteStrings<br>
exclusively in the API.<br>
<br>
Has a convention formed in the Haskell community on which strings<br>
should be used in APIs that pass strings around?<br>
<br>
In my case, blobs will anyway be passed around as ByteStrings.  But<br>
SQLite&#39;s C strings are UTF8 and some might prefer to Text over<br>
ByteStrings.  Or support both in the API?<br>
<br>
This matters in the low-level bindings too, where result accessors<br>
need to return either ByteStrings or Text objects for TEXT fields.<br>
Currently direct-sqlite uses the String type but Irene is thinking of<br>
changing the type to a more efficient representation<br>
(<a href="https://github.com/IreneKnapp/direct-sqlite/issues/3" target="_blank">https://github.com/IreneKnapp/direct-sqlite/issues/3</a>).<br>
<br>
Sqlite-simple links against both bytestring and text already, so from<br>
a purely package dependency point of view the choice doesn&#39;t really<br>
matter.  But sqlite-direct will need to choose one or the other for<br>
its string type in the SQLText s constructor.<br>
<br>
Any thoughts?<br>
<br>
Cheers,<br>
<br>
Janne<br>
<br>
_______________________________________________<br>
database-devel mailing list<br>
<a href="mailto:database-devel@haskell.org">database-devel@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/database-devel" target="_blank">http://www.haskell.org/mailman/listinfo/database-devel</a><br>
</blockquote></div><br></div>