[Haskell-cafe] Ridiculously slow FFI, or cairo binding?

Eugene Kirpichov ekirpichov at gmail.com
Wed Nov 2 15:03:29 CET 2011


Hi,

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).

On Wed, Nov 2, 2011 at 5:24 PM, Jean-Marie Gaillourdet
<jmg at gaillourdet.net>wrote:

> Hi Eugene,
>
> did you try using the SPECIALIZE pragma? It is part of the Haskell 98 and
> Haskell 2010 specifications.
>
> On 02.11.2011, at 12:14, Eugene Kirpichov wrote:
>
> > Yay!!!
> >
> > 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.
> >
> > 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?
> >
> > I am pretty sure I could have done the same with rewrite rules, but I
> tried for a while and to no avail.
> >
> > FAILED SOLUTION: rewrite rules
> > cFloatConv :: (RealFloat a, RealFloat b) => a -> b
> > cFloatConv  = realToFrac
> > {-# NOINLINE cFloatConv #-}
> > {-# RULES "cFloatConv/float2Double" cFloatConv = float2Double #-}
> > {-# RULES "cFloatConv/double2Float" cFloatConv = double2Float #-}
> > {-# RULES "cFloatConv/self"         cFloatConv = id           #-}
>
>
> See [1] in GHC User Guide.
>
> cFloatConv :: (RealFloat a, RealFloat b) => a -> b
> cFloatConv = realToFrac -- or try fromRational . toRational
>
> {-# SPECIALIZE cFloatConv :: Float -> Double #-}
> {-# SPECIALIZE cFloatConv :: Double -> Float #-}
>
> I did not try to compile or even benchmark this code. But I think it might
> help in your case.
>
> Cheers,
>  Jean
>
> [1]:
> http://www.haskell.org/ghc/docs/latest/html/users_guide/pragmas.html#specialize-pragma




-- 
Eugene Kirpichov
Principal Engineer, Mirantis Inc. http://www.mirantis.com/
Editor, http://fprog.ru/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111102/0390a412/attachment.htm>


More information about the Haskell-Cafe mailing list