If you just need to go back and forth from String to Text, why do you need to be generic? pack and unpack from Data.Text do the job.<br><br>Plus, in the way of what Christopher said, you can use the OverloadedStrings extension. You can then use the string syntax at a place that expects a text:<br>

<br>{-# LANGUAGE OverloadedStrings #-}<br>import Data.Text<br><br>t :: Text<br>t = &quot;Hello&quot;<br><br>Any instance of the IsString class can be used in this way, not only Text.<br><br><div class="gmail_quote">2012/3/8 Simon Hengel <span dir="ltr">&lt;<a href="mailto:sol@typeful.net">sol@typeful.net</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi!<br>
<br>
When writing library code that should work with both String and Text I<br>
find my self repeatedly introducing classes like:<br>
<br>
    class ToString a where<br>
      toString :: a -&gt; String<br>
<br>
    class ToText a where<br>
      toText :: a -&gt; Text<br>
<br>
(I use this with newtype wrapped value types backed by Text or<br>
ByteString.)<br>
<br>
So I wonder whether it would be a good idea to have a package that<br>
provides those classes.<br>
<br>
Or maybe just ToText, and provide default implementations of toString<br>
and toText, like:<br>
<br>
    class ToText a where<br>
<br>
      toText :: a -&gt; Text<br>
      toText = Text.pack . toString<br>
<br>
      toString :: a -&gt; String<br>
      toString = Text.unpack . toText<br>
<br>
How do you guys deal with that?  Any thoughts?<br>
<br>
Cheers,<br>
Simon<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>