Pragmas for FFI imports

John Meacham john at
Tue Feb 21 20:32:33 EST 2006

On Tue, Feb 21, 2006 at 04:50:20PM -0000, Simon Marlow wrote:
> First of all, my position on this has always been (since we argued about
> this during the design of the FFI) that include files and libraries
> should be kept out of the source file and specified separately, since
> they are a part of the build infrastructure, and vary across platforms.
> I lost the argument for include files, but this is why libraries cannot
> currently be specified inside source files.  Back in the FFI discussion,
> we didn't have Cabal, but now that we do, Cabal is the natural place to
> specify these things.

the problem is that package granularity is way to big for specifying
dependencies, jhc wants all dependencies attached to each FFI import.
the reason being that it collects only the dependencies for things that
are actually used so for instance the following works:

foreign import ccall "fcntl.h open" c_unix_open ...
foreign import ccall "win32.h OpenFile" c_win_open ...
foreign import lvm "lvmOpen" c_lvm_open ...

openFile = case os of
        "unix" -> ... c_unix_open ...
        "lvm" -> .... c_lvm_open ...
        "win32" ->..  c_win_open ...

and all the intermediate code remains platform independent.

now, I concur that this always isn't possible, but when it is I feel it
is the right way to do things. at least in jhcs model. requiring a
correlation between packages and C libraries would be overly restrictive
(but so would disallowing such a thing)

libraries are a little odd to keep in the source file, I am still
thinking about that, perhaps just a token will be propegated that the
build system can expand into the appropriate libs. in any case, I want
to assosiate dependencies with individual foreign calls. it makes
writing portable programs a whole lot simpler and obviates a lot of the
need for a preproccesor and generating different libraries for different

not that this is incompatable with package-wide dependencies, a
package-wide dependency would just be equivalent to adding the
dependency to every foreign call within that package.


John Meacham - ⑆⑆john⑈

More information about the Haskell-prime mailing list