String != [Char]

Johan Tibell johan.tibell at gmail.com
Mon Mar 19 16:53:31 CET 2012


On Mon, Mar 19, 2012 at 8:45 AM, Thomas Schilling
<nominolo at googlemail.com> wrote:
> Regarding the type class for converting to and from that type, there
> is a perhaps more complicated question: The current fromString method
> uses String as the source type which causes unnecessary overhead. This
> is unfortunate since GHC's built-in mechanism actually uses
> unpackCString[Utf8]# which constructs the inefficient String
> representation from a compact memory representation.  I think it would
> be best if the new fromString/fromText class allowed an efficient
> mechanism like that.  unpackCString# has type Addr# -> [Char] which is
> obviously GHC-specific.

I've been thinking about this question as well. How about

class IsString s where
    unpackCString :: Ptr Word8 -> CSize -> s

It's morally equivalent of unpackCString#, but uses standard Haskell types.

-- Johan



More information about the Haskell-prime mailing list