On Thu, May 31, 2007 at 11:36:54PM +0200, Tomasz Zielonka wrote: > You can imitate the C++ code using the FFI libraries: > > import Foreign.Storable > import Foreign > import Data.Word > import Data.Bits > > getDoubleBits :: Double -> IO String > getDoubleBits d = alloca $ \ptr -> do > poke ptr d > bs <- peekArray (sizeOf d) (castPtr ptr :: Ptr Word8) > return . concatMap (concatMap (show . fromEnum) . flip map [7,6..0] . > testBit) $ bs > > (I'm not sure this code prints bits in the right order). > You can generalize this to > getStorableBits :: Storable a => a -> IO String
Note also that you can use unsafePerformIO to safely get pure functions doing both these operations. -- David Roundy Department of Physics Oregon State University _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
