(i always forget to reply-to-all)<br><br>If you&#39;d like to reference C functions with Strings, one possible way is to<br>use System.Posix.DynamicLinker and the wrapper over libffi that&#39;s been<br>uploaded to hackage recently:<br>
<br>[m@monire asdf]$ ghci<br>GHCi, version 6.10.1: <a href="http://www.haskell.org/ghc/">http://www.haskell.org/ghc/</a>  :? for help<br>Loading package ghc-prim ... linking ... done.<br>Loading package integer ... linking ... done.<br>
Loading package base ... linking ... done.<br><br>ghci&gt; :m + Foreign.LibFFI<br>ghci&gt; :m + Foreign.Ptr Foreign.Storable<br>ghci&gt; :m + Foreign.C.Types Foreign.C.String<br>ghci&gt; :m + System.Posix.DynamicLinker<br>
<br>ghci&gt; malloc &lt;- dlsym Default &quot;malloc&quot;<br>Loading package unix-2.3.1.0 ... linking ... done.<br>ghci&gt; syscall &lt;- dlsym Default &quot;syscall&quot;<br><br>ghci&gt; :! echo -ne &quot;#include &lt;syscall.h&gt;\n__NR_execve\n&quot; | cpp | tac | grep -E &quot;^[0-9]+$&quot; | head -1 &gt; NOODLES<br>
ghci&gt; nr_execve :: CLong &lt;- (read . head . words) `fmap` readFile &quot;NOODLES&quot;<br>ghci&gt; :! rm -f NOODLES<br><br>ghci&gt; let sizeOfPtrCChar = sizeOf(undefined::Ptr())<br>ghci&gt; argv &lt;- callFFI malloc (retPtr (retPtr retCChar)) [argCSize (2*fromIntegral sizeOfPtrCChar)]<br>
Loading package bytestring-0.9.1.4 ... linking ... done.<br>Loading package libffi-0.1 ... linking ... done.<br><br>ghci&gt; sh &lt;- newCString &quot;/bin/sh&quot;<br>ghci&gt; poke argv sh<br>ghci&gt; poke (argv`plusPtr`sizeOfPtrCChar) 0<br>
<br>ghci&gt; callFFI syscall retCLong [argCLong nr_execve, argPtr sh, argPtr argv, argCInt 0] {-never returns-}<br>sh-3.2$ echo $0<br>/bin/sh<br>sh-3.2$ exit<br>exit<br>[m@monire asdf]$ <br><br>Matt<br><br><div class="gmail_quote">
On Fri, May 29, 2009 at 11:41 AM, Khudyakov Alexey <span dir="ltr">&lt;<a href="mailto:alexey.skladnoy@gmail.com">alexey.skladnoy@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Friday 29 of May 2009 19:34:44 Patrick LeBoutillier wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; Is it possible with Haskell to call a function whose name is contained<br>
&gt; in a String?<br>
&gt; Something like:<br>
&gt;<br>
&gt; five = call_func &quot;add&quot; [2, 3]<br>
&gt;<br>
&gt; If not, perhaps this is acheivable using FFI?<br>
&gt;<br>
</div>Or maybe you are asking for template haskell[1]. With it you can actually<br>
generate function at compile time. It depends on waht you actually need.<br>
<br>
&gt; {-# LANGUAGE TemplateHaskell #-}<br>
&gt; import <a href="http://Language.Haskell.TH" target="_blank">Language.Haskell.TH</a><br>
&gt;<br>
&gt; five = $( foldl appE (varE $ mkName &quot;+&quot;) [ litE $ integerL 2<br>
&gt;                                          , litE $ integerL 3 ] )<br>
<br>
<br>
[1] <a href="http://haskell.org/haskellwiki/Template_Haskell" target="_blank">http://haskell.org/haskellwiki/Template_Haskell</a><br>
<br>
--<br>
<font color="#888888">  Khudyakov Alexey<br>
</font><div><div></div><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br>