It evokes me Python&#39;s ctypes module.<br>Nice job ! I think It will be useful.<br><br><br><div class="gmail_quote">2011/3/6 Remi Turk <span dir="ltr">&lt;<a href="mailto:rturk@science.uva.nl">rturk@science.uva.nl</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I am happy to finally announce cinvoke 0.1, a binding to the<br>
C library cinvoke[1], allowing functions to be loaded and called<br>
whose names and types are not known before run-time.<br>
<br>
Why?<br>
<br>
Sometimes you can&#39;t use the Haskell foreign function interface<br>
because you parse the type of the function from somewhere else,<br>
i.e. you&#39;re writing an interpreter for a language that has an FFI<br>
itself.<br>
<br>
What?<br>
<br>
The main function it exports is:<br>
<br>
  cinvoke :: Symbol -&gt; RetType b -&gt; [Arg] -&gt; IO b<br>
<br>
And because code is worth a thousand words, here&#39;s a small program<br>
that uses libc to write a 1Gb buffer of random garbage to a file:<br>
<br>
&gt; module Main where<br>
&gt;<br>
&gt; import Foreign.CInvoke<br>
&gt;<br>
&gt; main = do<br>
&gt;     cxt &lt;- newContext<br>
&gt;     libc &lt;- loadLibrary cxt &quot;libc.so.6&quot;<br>
&gt;     malloc &lt;- loadSymbol libc &quot;malloc&quot;<br>
&gt;     creat  &lt;- loadSymbol libc &quot;creat&quot;<br>
&gt;     write  &lt;- loadSymbol libc &quot;write&quot;<br>
&gt;     free   &lt;- loadSymbol libc &quot;free&quot;<br>
&gt;     let sz = 2^30<br>
&gt;     buf &lt;- cinvoke malloc (retPtr retVoid)<br>
&gt;                                     [argCSize sz]<br>
&gt;     fd  &lt;- cinvoke creat  retCInt   [argString &quot;/tmp/test&quot;, argCUInt 0o644]<br>
&gt;     n   &lt;- cinvoke write  retCSize  [argCInt fd, argPtr buf, argCSize sz]<br>
&gt;     cinvoke free (retPtr retVoid) [argPtr buf]<br>
<br>
It hopefully works on any machine on which cinvoke works,<br>
but has only been tested on linux x86_64.<br>
As the current version of cinvoke only installs a static library,<br>
it does not work from GHCi at the moment (without hacking cinvoke<br>
to build a shared library).<br>
More interesting examples are included in examples/ in the<br>
package.<br>
<br>
Where?<br>
Hackage: <a href="http://hackage.haskell.org/package/cinvoke" target="_blank">http://hackage.haskell.org/package/cinvoke</a><br>
<br>
Cheers, Remi<br>
<br>
[1] <a href="http://www.nongnu.org/cinvoke/" target="_blank">http://www.nongnu.org/cinvoke/</a><br>
<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>
</blockquote></div><br>