<span class="gmail_quote"></span>Hello,<br><div><span class="q"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">There is one limitation to this, however. compileCall expects to compile a dynamic via 
GHC.dynCompileExpr;<br>what this means is your resource must be monomorphic (for Typeable to work.) As of right now, the easiest<br>way I can see to get around this is to simply define a datatype like such:<br><br>data Plugin {
<br> rsrc :: ... -- your type here<br>} deriving Typeable</blockquote></span><div><br>I have the same problem, although from a different direction. I am only interested in an eval-myDynamicFunction functionality not general modules, so I did it on a per function basis, using hs-plugins eval.
<br>A typeable data wrapper would be fine for me, although I have not yet found a non-ugly way to import needed modules for the plugin, as the plugin source would not be necessarily in the same place as the API. But thats rather an implementation detail.
<br><br>The real problem is, that I do not know, if there is an appropriate way to represent functions with a dynamic parameter count. As of now, I think it would need a bigger amount of hacking than it is worth to get rid of the workarounds I already have, but it would be interesting anyway.
<br>&nbsp;</div><span class="q"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> (unsafeCoerce# is an option but there&#39;s not a version<br>of compileCall to support this as of right now. I might add it if it seems needed.)
<br></blockquote></span></div><br>As I am relatively new, and since I have not found any introduction what unsafeCoerce is actually capable of (and how), I have ignored this possibility. Could someone give me some pointers? (the most useful thing I found is 
<a href="http://osdir.com/ml/lang.haskell.glasgow.bugs/2005-03/msg00048.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://osdir.com/ml/lang.haskell.glasgow.bugs/2005-03/msg00048.html</a>
)<br><br>The approach I stopped working at was:<br><pre><span>
<br>type TestSpecs = (String, String, String)</span></pre>
<pre><span>data</span> <span>FunctionTest</span> <span>=</span> <span>forall</span> <span>a</span> <span>b</span><span>
.</span> <span>(</span><span>Show</span> <span>a</span><span>,</span> <span>Show</span> <span>b</span><span>,</span> <span>
Eq</span> <span>b</span><span>)</span> <span>=&gt;</span> <br>                    <span>FunctionTest</span> <span>(</span><span>String<br></span><span>,</span> <span>[</span><span>a</span><span>]</span><span>,</span> <span>
(</span><span>a</span><span>
-&gt;</span><span>b</span><span>)</span><span>,</span> <span>[</span><span>b</span><span>]</span><span>)</span> <span>
deriving</span> <span>Typeable</span><br><span></span><br><span>readFunctionTest</span> <span>::</span> <span>TestSpecs</span> <span>
-&gt;</span> <span>IO</span> <span>(</span><span>Either</span> <span>[</span><span>String</span><span>]</span> <span>
(</span><span>Maybe</span> <span>FunctionTest</span><span>)</span><span>)</span><br><span>readFunctionTest</span> <span>(</span><span>
params</span><span>,</span><span>fn</span><span>,</span><span>predicted</span><span>)</span> <span>=</span> <span>eval_<br></span> <span>str</span> <span>[</span><span>&quot;FunctionTest&quot;</span><span>]</span> <span>
[</span><span>&quot;-i&quot;</span>
<span>++</span><span>libDir</span><span>]</span> <span>[]</span> <span>[</span><span>libDir</span><span>]</span><br>
    <span>where</span> <span>str</span> <span>=</span> <span>&quot;FunctionTest(&quot;</span><span>++</span><span>show</span> <span>
fn</span><span>++</span><span>&quot;, &quot;</span><span>++</span><span>params</span><span>++</span><span>&quot;, &quot;</span><span>
++</span><span>fn</span><span>++</span><span>&quot;, &quot;</span><span>++</span><span>pre</span><span>dicted++</span><span>&quot;)&quot;<br></span><br><br><span>applyFunctionTest</span> <span>::</span> <span>FunctionTest
</span> <span>-&gt;</span> <span>[</span><span>Bool<br></span><span>]</span><br><span>applyFunctionTest</span> <span>(</span><span>FunctionTest</span> <span>(</span><span>_</span><span>
,</span><span>parameters</span><span>,</span><span>function</span><span>,</span><span>predicted</span><span>)</span><span>
)</span> <span>=</span> <span>zipWith</span> <span>(</span><span>==</span><span>)</span> <span>(</span><span>map</span>
 <span>function</span> <span>parameters</span><span>)</span> <span>predicted</span></pre>..what works for general Functions with one Parameter. The wrapper ensures that the function takes one value to produce another value comparable to the other given value. So far, this looks ok to me, I can &#39;read&#39; a function once and apply it to multiple tests. However, if the function has more than one curried parameter, it has to be extended. I see the following approaches:
<br><br>-Do everything inside the eval (returning a [Bool] for example). That works, and I use it right now, but apart from being ugly, the function has to be read more than once. This might be a non-practical issue though.
<br><br>-Introduce constructors for each parameter count (up to a limit). <br><pre><span>FunctionTest2</span> <span>(</span><span>String</span><span>,</span> <span>
[</span><span>(a,a&#39;)</span><span>]</span><span>,</span> <span>(</span><span>a</span><span>-&gt;a&#39;-&gt;</span><span>
b</span><span>)</span><span>,</span> <span>[</span><span>b</span><span>]</span><span>)<br></span><span>applyFunctionTest<br></span> <span>(</span><span>FunctionTest</span>2 ...{-this might be generalizeable-}<span></span>
</pre>That is a lot more redundant and not as general as the inside-eval approach, but the function has to be read only once.
<br><br>-Convert any functions into ones that take one list/tuple parameter within the eval (assume there is no type ambiguity for simplicity). Partial application is not the goal here anyway and information about the parameter count could be obtained from the &quot;parameter&quot;-parameter or from additional information in the function String itself. 
<br>But for that a wrapper has to be added to the code inside eval that turns a function with unknown parameter count into the one actually exported. The type of this transformer function could be distinguished at eval compile time, but that means the implementation would have to be included in each eval...
<br><pre>uncurry3 fn (a, b, c) = fn a b c<br><span></span><span>uncurryN</span> = --would be defined using template Haskell or recursive data structures or something else I do not know yet<br>
--simpler as a list<br>uncurryL fn [] = fn<br>uncurryL fn (x:xs) = uncurryL (fn (fromValue x)) xs<br>-- but then the values would have to be wrapped for type ambiguity: data Value = IntV Int | ...<br></pre><br>I had a look on some techniques to deal with dynamic parameter count,
but they are either decided at runtime (as my understanding of
QuickCheck and its recursive data types is) or they do not represent functions with unknown parameter
count but only process one at a time (as Printf
does). Tell me if I am wrong.<br><br>So, I end up with three possibilities how to do the job (although I have not tried to implement all of them), but I am unhappy with each. How would one express a type &quot;a-&gt;...-&gt;b&quot; in Haskell (GHC)? Are you able to express the second approach without the redundant FunctionTestN definitions? I am willing to do ugly things, as long as I can restrict the effects to that particular place.
<br><br>Thanks,<br><span class="sg">Axel<br>
</span>