[Haskell-cafe] Why am I not allowed to use CStringLen inforeignexport?

Brian Hulley brianh at metamilk.com
Fri Sep 22 14:03:16 EDT 2006


Andreas Marth wrote:
>     low_l :: Word8 = fromIntegral (len .&. 0xFFFF)
>     low_h :: Word8 = fromIntegral (shiftR len 8 .&. 0xFFFF)
>     high_l :: Word8 = fromIntegral (shiftR len 16 .&. 0xFFFF)
>     high_h :: Word8 = fromIntegral (shiftR len 24 .&. 0xFFFF)

Hi -
I just noticed the mask should be changed to 0xFF for the BSTR8 version 
above.
Also, I'm not actually sure if a mask is needed at all. I just used one to 
make sure there would be no chance of an overflow exception being thrown, 
but the Haskell report doesn't seem to specify anything at all about the 
behaviour of (fromIntegral) when converting between types of different 
sizes.

Perhaps someone on the list can clarify whether or not a mask is needed ie 
is fromIntegral allowed to throw exceptions or does it always just silently 
discard unwanted bits of the argument being converted?

Thanks, Brian.
-- 
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 



More information about the Haskell-Cafe mailing list