
On Mon, Mar 19, 2012 at 9:02 AM, Christian Siefkes
wrote: On 03/19/2012 04:53 PM, Johan Tibell wrote:
I've been thinking about this question as well. How about
class IsString s where unpackCString :: Ptr Word8 -> CSize -> s
What's the Ptr Word8 supposed to contain? A UTF-8 encoded string?
Yes.
We could make a distinction between byte and Unicode literals and have:
class IsBytes a where unpackBytes :: Ptr Word8 -> Int -> a
class IsText a where unpackText :: Ptr Word8 -> Int -> a
In the latter the caller guarantees that the passed in pointer points to wellformed UTF-8 data.
Is there a reason not to put all these methods in the IsString class, with appropriate default definitions? You would need a UTF-8 encoder (& decoder) of course, but it would reduce the burden on clients and improve backwards compatibility. Cheers, Simon