Hi,<div><br></div><div>No, I didn't, as I read in the GHC docs that it is deprecated in favor of the RULES pragma (I wanted to replace specifically with floatToDouble and doubleToFloat).<br><br><div class="gmail_quote">
On Wed, Nov 2, 2011 at 5:24 PM, Jean-Marie Gaillourdet <span dir="ltr"><<a href="mailto:jmg@gaillourdet.net">jmg@gaillourdet.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Eugene,<br>
<br>
did you try using the SPECIALIZE pragma? It is part of the Haskell 98 and Haskell 2010 specifications.<br>
<div class="im"><br>
On 02.11.2011, at 12:14, Eugene Kirpichov wrote:<br>
<br>
> Yay!!!<br>
><br>
> I made a small change in Types.chs and got my original cairo-binding-based program to be just as blazing fast. The only problem I have with this is that I used multiparameter type classes.<br>
><br>
> Dear gtk2hs team! Is it possible to incorporate my changes? I'm pretty sure people will be happy by an order-of-magnitude speedup. Probably the stuff could be wrapped in #define's for those who aren't using GHC and can't use multiparameter type classes?<br>
><br>
> I am pretty sure I could have done the same with rewrite rules, but I tried for a while and to no avail.<br>
><br>
> FAILED SOLUTION: rewrite rules<br>
> cFloatConv :: (RealFloat a, RealFloat b) => a -> b<br>
> cFloatConv = realToFrac<br>
> {-# NOINLINE cFloatConv #-}<br>
> {-# RULES "cFloatConv/float2Double" cFloatConv = float2Double #-}<br>
> {-# RULES "cFloatConv/double2Float" cFloatConv = double2Float #-}<br>
> {-# RULES "cFloatConv/self" cFloatConv = id #-}<br>
<br>
<br>
</div>See [1] in GHC User Guide.<br>
<div class="im"><br>
cFloatConv :: (RealFloat a, RealFloat b) => a -> b<br>
</div>cFloatConv = realToFrac -- or try fromRational . toRational<br>
<br>
{-# SPECIALIZE cFloatConv :: Float -> Double #-}<br>
{-# SPECIALIZE cFloatConv :: Double -> Float #-}<br>
<br>
I did not try to compile or even benchmark this code. But I think it might help in your case.<br>
<br>
Cheers,<br>
Jean<br>
<br>
[1]: <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/pragmas.html#specialize-pragma" target="_blank">http://www.haskell.org/ghc/docs/latest/html/users_guide/pragmas.html#specialize-pragma</a></blockquote>
</div><br><br clear="all"><div><br></div>-- <br>Eugene Kirpichov<br>Principal Engineer, Mirantis Inc. <a href="http://www.mirantis.com/" target="_blank">http://www.mirantis.com/</a><br>Editor, <a href="http://fprog.ru/" target="_blank">http://fprog.ru/</a><br>
</div>