<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-02-11 16:18 GMT+01:00 Francesco Mazzoli <span dir="ltr"><<a href="mailto:f@mazzo.li" target="_blank">f@mazzo.li</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Relatedly, if I have some function pointer known at runtime that<br>
addresses a C function that takes some arguments, I have no way to<br>
invoke it from Haskell, since all FFI imports must be declared at<br>
compile-time, and I don't know the address of the symbol I want to<br>
execute at compile time.<br></blockquote></div><br>You can use FunPtr and wrapper imports to convert a FunPtr into a Haskell function. <br><a href="https://hackage.haskell.org/package/base-4.7.0.2/docs/Foreign-Ptr.html#g:2">https://hackage.haskell.org/package/base-4.7.0.2/docs/Foreign-Ptr.html#g:2</a><br><br>You may be interested in my dynamic-linker-template package [1] to avoid having to write boilerplate wrappers. For now it only works with dynamic linking from System.Posix.DynamicLinker, but it could be easily extended to support other platforms. It automatically generates wrappers for all the functions in a record as well as the code to load symbol addresses and to convert them into Haskell functions (examples [2,3]).<br><br>Sylvain<br><br>[1] <a href="https://hackage.haskell.org/package/dynamic-linker-template">https://hackage.haskell.org/package/dynamic-linker-template</a><br>[2] <a href="https://github.com/hsyl20/dynamic-linker-template/blob/master/Tests/Test.hs">https://github.com/hsyl20/dynamic-linker-template/blob/master/Tests/Test.hs</a><br>[3] <a href="https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/OpenCL/Library.hs">https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/OpenCL/Library.hs</a><br></div></div>