[Haskell-cafe] Re: ANNOUNCE: protocol-buffers-0.2.9 for Haskell is ready

Simon Marlow marlowsd at gmail.com
Tue Sep 23 15:22:18 EDT 2008


Chris Kuklewicz wrote:
> I am cross-posting this message to several lists.
> 
> I had learned the trick before the documentation was updated.  It seems 
> I have used a very unreliable trick.  And the "use castToSTUArray" 
> suggested alternative is a really poor one since I am not using arrays 
> at all.

castSTUArray is the way GHC does it - the idea is to allocate a small 
array, store the Float/Double in it, cast the type of the array to 
Word32 or whatever, and then read out the contents.

It's more or less equivalent to the peek/poke solution, except that it 
doesn't need unsafePerformIO.

GHC's code is here: (look for floatToWord):

http://darcs.haskell.org/ghc/compiler/cmm/PprC.hs

Cheers,
	Simon



More information about the Haskell-Cafe mailing list