Hi,<br>Thanks for your reply!<br>I made some changes according to your suggest. Now I get rid of <br>argument p. Unfortunately, GHC is not smart enough to memorize<br>this true polymorphic constant.<br>Can you give some hints on what kind of specialize pragmas I should<br>

use?<br><br>Regards,<br>Bin Jin<br><br><br><div class="gmail_quote">On Tue, Nov 8, 2011 at 2:35 PM,  <span dir="ltr">&lt;<a href="mailto:oleg@okmij.org">oleg@okmij.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><br>
Bin Jin wrote:<br>
<br>
&gt; Here is a function that will be called everytime by `(*)` in `Num` typeclass<br>
</div><div class="im">&gt; &gt; montgKeys :: (PostiveN p, Integral a, Bits a) =&gt; p -&gt; a<br>
&gt;<br>
</div><div class="im">&gt; as you can imagine, I always pass (undefined :: p) as parameter to<br>
&gt; `montgKeys`, so if it&#39;s handled well, it should be memorized for<br>
&gt; future usage. But tracing shows that both `p2num` and `montgKeys` are<br>
&gt; evaluated every time being called.<br>
<br>
</div>First of all, let us get rid of the argument p. Let&#39;s define<br>
<br>
&gt; newtype W p a = W{unW:: a}<br>
<br>
then we can easily re-write montgKeys to give it the following signature:<br>
<br>
&gt; &gt; montgKeys :: (PostiveN p, Integral a, Bits a) =&gt; W p a<br>
<br>
You can use ScopedTypevariables to set the needed &#39;p&#39; from the context.<br>
<br>
So, montgKeys becomes a polymorphic constant, quite like minBound.<br>
Now, the hope is that when the types p and a are determined, GHC could<br>
specialize montgKeys and turn it into a real constant. Perhaps some<br>
RULE or specialize pragmas may help...<br>
<br>
<br>
<br>
</blockquote></div><br>