<div dir="ltr"><div><div>Hello,</div><div><br></div><div>I have a TH feature request and I'd like to hear what people have to say about it. Here is the [Trac ticket][0].</div><div>I'm new to this, so if anything here sounds completely wrong, it probably is.</div><div><br></div><div>TH currently lets you add in arbitrary C (and other languages usually supported by C compilers).</div><div>That code is compiled for you and then linked in automatically. This is what makes the</div><div>[`inline-c`][1] package possible.</div><div><br></div><div>I'm proposing to extend this so that TH lets you pass in something that is already compiled and</div><div>ready to be linked. The idea is that this would allow TH-level FFI to any language that can</div><div>produce object files or libraries that have the C ABI. My immediate use-case is to make an</div><div>`inline-rust` package where one can write Rust code straight into a Haskell quasiquote.</div><div><br></div><div>In terms of a concrete API change, it would suffice to</div><div><br></div><div>  1. add a `LangLinkable` constructor to the `ForeignSrcLang` data type</div><div>  2. add a `qAddForeignFilePath :: ForeignSrcLang -> FilePath -> m ()` method to `Quasi`</div><div><br></div><div>The code change is pretty small too (60 additions, 30 deletions) since the `addForeignFile`</div><div>machinery is fully reusable (we just have to skip past the phase of calling the C compiler).</div><div><br></div><div><div># Pros:</div><div><br></div><div>  * Better TH FFI support</div><div>  * Simple to implement</div><div><br></div><div># Cons:</div><div><br></div><div>  * The proposed API is suboptimal: it allows for `qAddForeignFile LangLinkable "..."` although that </div><div> that pretty much never makes sense since the thing being linked is not subject to `String`  encoding</div></div><div><br></div><div>Any thoughts?</div><div><br></div><div>Alec</div></div><div><br></div><div>  [0]: <a href="https://ghc.haskell.org/trac/ghc/ticket/14298" target="_blank">https://ghc.haskell.org/t<wbr>rac/ghc/ticket/14298</a></div><div>  [1]: <a href="https://hackage.haskell.org/package/inline-c" target="_blank">https://hackage.haskell.o<wbr>rg/package/inline-c</a><br></div></div>