<div dir="ltr">Hi,<br><br>The FFI pages on the wiki are not really in a good shape in my opinion (especially for newcomers).<br><br>I have started a fresh one here: <a href="https://wiki.haskell.org/Foreign_Function_Interface_(FFI)">https://wiki.haskell.org/Foreign_Function_Interface_(FFI)</a><br><br>This is just the first draft. I will improve it, probably split it in several pages and merge information from other pages, especially pages linked on <a href="https://wiki.haskell.org/FFI">https://wiki.haskell.org/FFI</a><br><br>Sylvain<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-12 10:02 GMT+01:00 Simon Peyton Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">| Thanks to everyone who replied!<br>
|<br>
| It seems like that through a combination of facilities like `libffi'<br>
| and `addTopDecls' I can do everything that I wanted to do.<br>
<br>
</span>Great.  But please, please, do write up what you learned on the FFI wiki page<br>
        <a href="https://wiki.haskell.org/GHC/Using_the_FFI" target="_blank">https://wiki.haskell.org/GHC/Using_the_FFI</a><br>
<span class="HOEnZb"><font color="#888888"><br>
Simon<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
| -----Original Message-----<br>
| From: Francesco Mazzoli [mailto:<a href="mailto:f@mazzo.li">f@mazzo.li</a>]<br>
| Sent: 12 February 2015 09:00<br>
| To: Simon Peyton Jones<br>
| Cc: Michael Sloan; Manuel Chakravarty; Geoffrey Mainland<br>
| (<a href="mailto:mainland@cs.drexel.edu">mainland@cs.drexel.edu</a>); <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>; haskell<br>
| Subject: Re: [Haskell-cafe] Anonymous FFI calls<br>
|<br>
| Thanks to everyone who replied!<br>
|<br>
| It seems like that through a combination of facilities like `libffi'<br>
| and `addTopDecls' I can do everything that I wanted to do.<br>
|<br>
| I still want to take a shot at implementing anonymous FFI calls, since<br>
| IMHO I think they are a very small but useful addition to the<br>
| language.<br>
|<br>
| Francesco<br>
|<br>
| On 12 February 2015 at 09:29, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>><br>
| wrote:<br>
| > |  Also, I meant to say that addTopDecls is only exported by<br>
| > |  "Language.Haskell.TH.Syntax".  While this is a digression, there are<br>
| a<br>
| > |  few other handy functions that are oddly left out of<br>
| > |  "<a href="http://Language.Haskell.TH" target="_blank">Language.Haskell.TH</a>": addDependentFile, addModFinalizer, and<br>
| possibly<br>
| > |  more.<br>
| ><br>
| > That does seem wrong.  Do make a patch!<br>
| ><br>
| > SIMon<br>
| ><br>
| > |<br>
| > |  -Michael<br>
| > |<br>
| > |  On Wed, Feb 11, 2015 at 3:25 PM, Simon Peyton Jones<br>
| > |  <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>> wrote:<br>
| > |  > I would LOVE someone to improve the documentation for addTopDecls.<br>
| > |  Manuel Chakravarty and Geoff Mainland were responsible for the<br>
| > |  implementation.<br>
| > |  ><br>
| > |  > Simon<br>
| > |  ><br>
| > |  > | -----Original Message-----<br>
| > |  > | From: ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org">ghc-devs-bounces@haskell.org</a>] On Behalf<br>
| Of<br>
| > |  > | Michael Sloan<br>
| > |  > | Sent: 11 February 2015 23:19<br>
| > |  > | To: Francesco Mazzoli<br>
| > |  > | Cc: <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>; haskell<br>
| > |  > | Subject: Re: [Haskell-cafe] Anonymous FFI calls<br>
| > |  > |<br>
| > |  > | It seems like addTopDecls[1] will able to help here.<br>
| > |  Unfortunately,<br>
| > |  > | the function is not well documented and not very discoverable<br>
| > |  > | because it's only exported by <a href="http://Language.Haskell.TH" target="_blank">Language.Haskell.TH</a>.<br>
| > |  > |<br>
| > |  > | The documentation doesn't mention that it can only be used to<br>
| > |  create<br>
| > |  > | new top level functions and FFI imports[2].  I think that adding<br>
| > |  FFI<br>
| > |  > | imports was the main motivation for implementing it.   In the<br>
| past<br>
| > |  > | I've wanted to generate instances via this function, but<br>
| > |  > | unfortunately it's not implemented..<br>
| > |  > |<br>
| > |  > | Hope that helps!<br>
| > |  > | -Michael<br>
| > |  > |<br>
| > |  > | [1] <a href="http://hackage.haskell.org/package/template-haskell-" target="_blank">http://hackage.haskell.org/package/template-haskell-</a><br>
| > |  > | <a href="http://2.9.0.0/docs/Language-Haskell-TH-Syntax.html#v:addTopDecls" target="_blank">2.9.0.0/docs/Language-Haskell-TH-Syntax.html#v:addTopDecls</a><br>
| > |  > |<br>
| > |  > | [2]<br>
| > |  > |<br>
| > |  <a href="https://github.com/ghc/ghc/blob/1d982ba10f590828b78eba992e73315dee33" target="_blank">https://github.com/ghc/ghc/blob/1d982ba10f590828b78eba992e73315dee33</a><br>
| > |  > | f78a/<br>
| > |  > | compiler/typecheck/TcSplice.hs#L818<br>
| > |  > |<br>
| > |  > | On Wed, Feb 11, 2015 at 2:26 AM, Francesco Mazzoli <<a href="mailto:f@mazzo.li">f@mazzo.li</a>><br>
| > |  wrote:<br>
| > |  > | > Hi,<br>
| > |  > | ><br>
| > |  > | > I am in a situation where it would be very useful to call C<br>
| > |  > | > functions without an explicit FFI import.  For example, I'd<br>
| like<br>
| > |  > | > to be able to do<br>
| > |  > | ><br>
| > |  > | >     (foreign import ccall "cadd" :: CInt -> CInt -> CInt) 1 2<br>
| > |  > | ><br>
| > |  > | > instead of declaring the foreign import explicitely at the top<br>
| > |  level.<br>
| > |  > | ><br>
| > |  > | > Is there a way to do this or to achieve similar results in<br>
| some<br>
| > |  > | > other way?<br>
| > |  > | ><br>
| > |  > | > If not, I imagine it would be easy to implement such a<br>
| facility<br>
| > |  in<br>
| > |  > | > GHC, given that the code implementing calling to C functions<br>
| > |  must<br>
| > |  > | > already be present to implement "proper" FFI imports.  I think<br>
| > |  > | > such an addition would be useful in many cases.<br>
| > |  > | ><br>
| > |  > | > Thanks,<br>
| > |  > | > Francesco<br>
| > |  > | > _______________________________________________<br>
| > |  > | > Haskell-Cafe mailing list<br>
| > |  > | > <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
| > |  > | > <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
| > |  > | _______________________________________________<br>
| > |  > | ghc-devs mailing list<br>
| > |  > | <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
| > |  > | <a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
</div></div></blockquote></div><br></div>