[Haskell-cafe] fromString and toString

Ben Foppa benjamin.foppa at gmail.com
Tue Feb 4 13:55:47 UTC 2014

I know we have

class IsString a where
    fromString :: String -> a

But do we have an inverse generic function toString defined anywhere?
IsString implies that the type `a` is a subset of String; if all we have is
fromString, then IsString defines *supersets* of String. To me, the most
logical thing would be that IsString defines bijections to String (i.e.
things that are subsets *and* supersets).

The reason this came up is that I'm getting pretty sick of type-juggling
different string types from different libraries (String, Text, various
ByteStrings), especially since I have to tweak all the functions I use if a
type changes; discovering fromString was fantastic, but without toString, I
can't define something like

reString :: (IsString a, IsString b) => a -> b

which is great to have if your putStrLn only accepts one kind of string,
and you have several distinct ones floating around.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140204/6dc00795/attachment.html>

More information about the Haskell-Cafe mailing list