[Haskell-cafe] Re: Additonal types for Foreign.C.Types

Ross Mellgren rmm-haskell at z.odi.ac
Tue Feb 10 16:13:41 EST 2009


The FFI spec says (at http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise3.html#x6-120003.2) 
:

The argument types at[i] produced by fatype must be marshallable  
foreign types; that is, each ati is either (1) a basic foreign type or  
(2) a type synonym or renamed datatype of a marshallable foreign type.  
Moreover, the result type rt produced by frtype must be a marshallable  
foreign result type; that is, it is either a marshallable foreign  
type, the type (), or a type matching Prelude.IO t, where t is a  
marshallable foreign type or ().

Earlier it defines the basic foreign types:

  The following types constitute the set of basic foreign types:

     * Char, Int, Double, Float, and Bool as exported by the Haskell  
98 Prelude as well as
     * Int8, Int16, Int32, Int64, Word8, Word16, Word32, Word64, Ptr  
a, FunPtr a, and StablePtr a, for any type a, as exported by Foreign  
(Section 5.1).

So, that list of types, or any type synonym.

-Ross


On Feb 10, 2009, at 3:56 PM, Maurí cio wrote:

> 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?
>
> Thanks,
> Maurício
>
>> 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
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list