
On Monday 12 February 2007 09:54, Yitzchak Gale wrote:
Bulat Ziganshin wrote:
examples of lifting C functions into Haskell world:
mysin :: Double -> Double mysin = realToFrac . c_mysin . realToFrac
-- c_mysin :: CDouble -> CDouble
rnd :: Int -> IO Int rnd x = do r <- c_rnd (fromIntegral x) return (fromIntegral r)
-- c_rnd :: CInt -> IO CInt
OK, got it. I'll put that in.
Just a small note here: GHC and the base library are both very careful to completely eliminate things like realToFrac or fromIntegeral in code similar to the one above, if the representations of the Haskell type and the C type are identical. Therefore there is no need to sacrifice portability for speed by leaving these conversion function out and making invalid assumptions. If actual conversion code is generated without a good reason, I would consider this as a bug. Cheers, S.