
Hello,
On 1/28/07, Duncan Coutts
We can put them in the IO monad. The same applies to packCStringLen and packMallocCString.
Adding packCString (and friends) to the IO monad does not make them any safer (the IO monad hides some sins but not all ;-). To see the problem, imagine that packCString was of type "CString -> IO ByteString" (as Don suggested). Then we still get the same weird behavior if we replace: let s = packCString x with s <- packCString x in the example that I posted. The problem is that 'x' allows us to mutate the memory area occupied by s' but Haskell values are supposed to be immutable. So if we want to have these functions, then it seems that the best we can do is to mark them with the "unsafe" label and be very careful how we use them... Out of curiosity (I have not looked at the implementation of ByteString) is it true that ByteStrings created in this fashion (i.e., with packCString) will not be garbage collected? -Iavor