2010/8/13 Bryan O&#39;Sullivan <span dir="ltr">&lt;<a href="mailto:bos@serpentine.com">bos@serpentine.com</a>&gt;</span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="gmail_quote">2010/8/13 Gábor Lehel <span dir="ltr">&lt;<a href="mailto:illissius@gmail.com" target="_blank">illissius@gmail.com</a>&gt;</span><div class="im"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div></div><div>How about the case for text which is guaranteed to be in ascii/latin1?</div></div>
ByteString again?<br></blockquote><div> </div></div></div>If you know it&#39;s text and not binary data you are working with, you should still use Data.Text. There are a few good reasons.<div><ol><li>The API is more correct. For instance, if you use Text.toUpper on a string containing latin1 &quot;<span style="font-family:verdana, arial, helvetica, code2000, sans-serif;border-collapse:collapse">ß&quot; (eszett, sharp S), you&#39;ll get the two-character sequence &quot;SS&quot;, which is correct. Using Char8.map Char.toUpper here gives the wrong answer.</span></li>


<li><span style="font-family:verdana, arial, helvetica, code2000, sans-serif;border-collapse:collapse">In many cases, the API is easier to use, because it&#39;s oriented towards using text data, instead of being a port of the list API.</span></li>


<li><span style="font-family:verdana, arial, helvetica, code2000, sans-serif;border-collapse:collapse">Some commonly used functions, such as substring searching, are <i>way</i> faster than their ByteString counterparts.</span></li>


</ol></div>
</blockquote></div>These are all good reasons. An even more important reason is type safety:<div><br></div><div>A function that receives a Text argument has the guaranteed that the input is valid Unicode. A function that receives a ByteString doesn&#39;t have that guarantee and if validity is important the function must perform a validity check before operating on the data. If the function does not validate the input the function might crash or, even worse, write invalid data to disk or some other data store, corrupting the application data.</div>

<div><br></div><div>This is a bit of a subtle point that you really only see once systems get large. Even though you might pay for the conversion from ByteString to Text you might make up for that by avoiding several validity checks down the road.</div>

<div><br></div><div>Cheers,</div><div>Johan</div><div><br></div>