FFI Help
Malcolm Wallace
Malcolm.Wallace@cs.york.ac.uk
Wed, 4 Jun 2003 10:47:45 +0100
> > > foreign import ccall "math.h signgam" signgamC :: IO Int
>
> signgam is an "int" variable, but this assumes that it is a function
> of type "int signgam(void)".
>
> Write a C wrapper "int get_signgam(void) { return signgam; }" and
> import that.
Or alternatively, foreign import the address of the int and read it
directly with 'peek'.
import Foreign
...
foreign import ccall "math.h &signgam" signgamC :: Ptr Int32
...
gammaIO :: Double -> IO Double
gammaIO x = do lg <- lgammaC x
s <- peek signgamC
return $ fromIntegral s * exp lg
Regards,
Malcolm