<div dir="ltr"><div><div><div><div><div>I know we have<br><br><span style="font-family:courier new,monospace">class IsString a where<br></span></div><span style="font-family:courier new,monospace">    fromString :: String -> a</span><br>
<br></div>But do we have an inverse generic function <span style="font-family:courier new,monospace">toString</span> defined anywhere? <span style="font-family:courier new,monospace">IsString</span> implies that the type <span style="font-family:courier new,monospace">`a`</span> is a subset of <span style="font-family:courier new,monospace">String</span>; if all we have is <span style="font-family:courier new,monospace">fromString</span>, then <span style="font-family:courier new,monospace">IsString</span> defines <i>supersets</i> of String. To me, the most logical thing would be that <span style="font-family:courier new,monospace">IsString</span> defines bijections to String (i.e. things that are subsets <i>and</i> supersets).<br>
<br></div>The reason this came up is that I'm getting pretty sick of type-juggling different string types from different libraries (<span style="font-family:courier new,monospace">String, Text,</span> various <span style="font-family:courier new,monospace">ByteString</span>s), especially since I have to tweak all the functions I use if a type changes; discovering <span style="font-family:courier new,monospace">fromString</span> was fantastic, but without <span style="font-family:courier new,monospace">toString</span>, I can't define something like<br>
<br><span style="font-family:courier new,monospace">reString :: (IsString a, IsString b) => a -> b</span><br><br></div>which is great to have if your <span style="font-family:courier new,monospace">putStrLn</span> only accepts one kind of string, and you have several distinct ones floating around.<br>
<br></div>Thanks,<br>Ben<br></div>