
28 May
2011
28 May
'11
9:06 p.m.
Michael Snoyman wrote:
main = do fromAddr <- unsafePackAddressLen 7 $(return $ LitE $ StringPrimL "123\0\&456") print fromAddr let fromStr = S.pack $ map (toEnum . fromEnum) $(return $ LitE $ StringL "123\0\&456") print fromStr
I get the result:
"123\192\128\&45" "123\NUL456"
Well, the haddocks for StringPrimL say: A primitive C-style string, type Addr# You obviously can't have a null byte in the middle of a C-style string. So GHC is replacing it with an invalid UTF-8 representation of a null byte, the best it can do under the circumstances. Then you just get those bytes back when you read them as a byte string. Yitz