[Haskell-cafe] Re: Additonal types for Foreign.C.Types
bulat.ziganshin at gmail.com
Tue Feb 10 16:18:35 EST 2009
Tuesday, February 10, 2009, 11:56:40 PM, you wrote:
1. haskell compiler should check that your haskell imports match C
function prototypes. ghc does it in -fvia-C mode if you declare .h
file where the function prototype may be found:
foreign import ccall unsafe "Environment.h UpdateCRC"
c_UpdateCRC :: Ptr CChar -> CUInt -> CUInt -> IO CUInt
but who now uses -fvia-C mode?
2. there is correspondence between C and Haskell types. haskell
equivalents for C tpes are defined in FFI addendum. C equivalents for
GHC haskell types are defined in ghc .h files, these are things like
HsInt and so on
if you use, for example, Int type on haskell side and int on C side,
they may turn out to be the same or not. if you don't use -fvia-C and
.h file, you will not get even a warning - program will just stop
i think that we may propose changing FFI addendum so that haskell
compilers guarantees correspondence between Int16 and int16_t and so on
disclaimer: i don't used ghc versions after 6.6, so things may be
worse or better now :)
> Yes, I can. Thanks. Just forget my idea, with
> this I can provide all those types in a library.
> I'm confused. When is it possible to use a type
> as a parameter to a foreign function call? My
> first guess was that I had to provide an instance
> for class Storable, but after I tried writing
> a complex-like type that way GHC told me my type
> was unaceptable. So I thought only types allowed
> by the compiler (including forall a. Ptr a) could
> be used that way.
> What is the rule? I've read all of FFI report
> and found nothing. Did I miss something? How can
> I make a type of mine acceptable? Why are
> Data.Int acceptable, and how could I know that?
>> I think you can use Data.Word and Data.Int types for this, that is.
>>> After reading an ISO draft for standard C, I found
>>> a few types that could be usefull when binding to
>>> libraries (these are from <stdint.h>):
>>> int8_t, uint8_t, int16_t, uint16_t, int32_t,
>>> uint32_t, int64_t, uint64_t
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe