Re: Import, how to
I'm a beginner at haskell and ffi. I was trying to import and use is haskell one C function, but I can't manage to do that. Can someone show me an example how to create an import and a use example for such a C function: char functionName(char *, unsigned int, char *) {-# LANGUAGE ForeignFunctionInterface #-} module FOo where import Foreign import Foreign.C import Data.Word foreign import ccall "functionName" functionName_inC :: CString -> Word -> CString -> IO CChar -- Assuming you really want to use Haskell Strings and Ints etc -- and furthermore if the C function is really pure, -- add the following wrapper. functionName_h :: String -> Int -> String -> Char functionName_h s0 i s1 = unsafePerformIO $ withCString s0 $ \cs0-> withCString s1 $ \cs1-> do cchar <- functionName_inC cs0 (fromIntegral i) cs1 return (castCCharToChar cchar) Regards, Malcolm ___ FFI mailing list FFI@haskell.org http://www.haskell.org/mailman/listinfo/ffi
Re: Import, how to
On Sun, 18 Jul 2010, grzyb wrote: I'm a beginner at haskell and ffi. I was trying to import and use is haskell one C function, but I can't manage to do that. Can someone show me an example how to create an import and a use example for such a C function: char functionName(char *, unsigned int, char *) Something like foreign import functionName :: Ptr CChar -> CUInt -> Ptr CChar -> IO CChar ___ FFI mailing list FFI@haskell.org http://www.haskell.org/mailman/listinfo/ffi
Import, how to
Hi, I'm a beginner at haskell and ffi. I was trying to import and use is haskell one C function, but I can't manage to do that. Can someone show me an example how to create an import and a use example for such a C function: char functionName(char *, unsigned int, char *) -- View this message in context: http://old.nabble.com/Import%2C-how-to-tp29199694p29199694.html Sent from the Haskell - FFI mailing list archive at Nabble.com. ___ FFI mailing list FFI@haskell.org http://www.haskell.org/mailman/listinfo/ffi