Proposal: Allow passing in linkable files from TH
alec.theriault at gmail.com
Tue Oct 3 03:58:18 UTC 2017
I have a TH feature request and I'd like to hear what people have to say
about it. Here is the [Trac ticket].
I'm new to this, so if anything here sounds completely wrong, it probably
TH currently lets you add in arbitrary C (and other languages usually
supported by C compilers).
That code is compiled for you and then linked in automatically. This is
what makes the
[`inline-c`] package possible.
I'm proposing to extend this so that TH lets you pass in something that is
already compiled and
ready to be linked. The idea is that this would allow TH-level FFI to any
language that can
produce object files or libraries that have the C ABI. My immediate
use-case is to make an
`inline-rust` package where one can write Rust code straight into a Haskell
In terms of a concrete API change, it would suffice to
1. add a `LangLinkable` constructor to the `ForeignSrcLang` data type
2. add a `qAddForeignFilePath :: ForeignSrcLang -> FilePath -> m ()`
method to `Quasi`
The code change is pretty small too (60 additions, 30 deletions) since the
machinery is fully reusable (we just have to skip past the phase of calling
the C compiler).
* Better TH FFI support
* Simple to implement
* The proposed API is suboptimal: it allows for `qAddForeignFile
LangLinkable "..."` although that
that pretty much never makes sense since the thing being linked is not
subject to `String` encoding
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ghc-devs