extended foreign decls

Manuel M. T. Chakravarty chak at cse.unsw.edu.au
Tue Jan 2 05:55:46 EST 2001

[This comment is a bit late, I know...]

malcolm-ffi at cs.york.ac.uk wrote,

> Fergus writes, triggered by my suggestion of "foreign value":
> > Mercury supports this using `foreign_decls' and `foreign_code' pragmas.
> I refrained from proposing this in an earlier mail, but I've been
> thinking about it for a long time.  I *really* *really* want to be
> able to insert small snippets of foreign code into the source of
> a Haskell module.
> GreenCard allows you to do this, via the %- or %C directives.  It is
> one of the features I miss most about the new FFI.  I know that it
> is always possible to write a small .c file and compile and link it
> in separately, but with the new FFI that now seems to necessitate
> writing an additional .h file as well.  And all for a handful of lines
> of foreign code that could easily be kept in the Haskell source, with
> the ease-of-comprehension benefits entailed by keeping everything
> together that belongs together.

I believe that functionality like this should be implemented
by an extra tool rather than the Haskell compiler.
GreenCard does it, hsc2hs has something similar, and I am
considering a similar facility for c2hs.

I completely agree with your motivation of keeping small
foreign code snippets inline to make the interface easier to
comprehend and maintain.  This is, however, a good indicator
that we should use an extra tool.  IMHO, the FFI language
extension should me as small as possible.  Convenience
should be provided by extra tools.  Unless, the feature is
impossible (or very hard) to implement as an extra tool, but
I am not convinced that this is the case here.


More information about the FFI mailing list