Binding to inline functions

Simon Marlow marlowsd at gmail.com
Wed Aug 26 04:18:55 EDT 2009


On 25/08/2009 13:45, Maurí­cio CA wrote:
>>>> I understand we can't use 'foreign import ccall'
>>>> to wrap inline C functions. Do you think it could
>>>> be possible to have an option in cabal to generate
>>>> such functions in an object file when #included in
>>>> a C file, in a compiler independent, portable way?
>
>> I think it would be easy to do in GHC. We already have the machinery
>> to generate the _stub.c files and compile them.
>>
>> The main question is what the syntax should look like. I was toying with
>>
>> foreign import capi "foo" foo :: ...
>
> Under that syntax, how would GHC know where to find
> declaration/definition for a function? Since it's not,
> by hypothesis, on an object or library file, a C file
> will have to be compiled to get both the declaration
> and the definition.

Yes, absolutely.  GHC will inject a C wrapper function into the _stub.c 
file, compile it, and then call the wrapper from Haskell.

Cheers,
	Simon


More information about the Libraries mailing list