<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>The -fno-method-sharing flag was supposed to be a bit
experimental, which is why it takes the cheap-and-cheerful route of being a
static flag. (Only dynamic flags can go in OPTIONS_GHC.)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>What it does is this. When you call an overloaded function f ::
C a => a -> a, in a function<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:36.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>g = ...f...f...<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:36.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>you normally get something like this<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-indent:36.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>fint :: Int -> Int<o:p></o:p></span></p>
<p class=MsoNormal style='text-indent:36.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>fint = f Int dCInt<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-indent:36.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>g = ...fint...fint...<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>That is, ‘fint’ extracts the ‘f’ method
from dCInt::C Int, and it’s then used repeatedly. <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>With -fno-method-sharing you get<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-indent:36.0pt'><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>g = ...(f Int dCInt)
... (f Int dCInt)...<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>So the record selection is duplicated. It shouldn’t
make much difference, but of course it *<b>does</b>* when rules are involved,
because there are no rules for fint (it’s a fresh, local function).
<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Simon<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'> glasgow-haskell-users-bounces@haskell.org
[mailto:glasgow-haskell-users-bounces@haskell.org] <b>On Behalf Of </b>Conal
Elliott<br>
<b>Sent:</b> 07 June 2008 17:26<br>
<b>To:</b> glasgow-haskell-users@haskell.org<br>
<b>Subject:</b> Re: desperately seeking RULES help<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>Is it by intention that
-fno-method-sharing works only from the command line, not in an OPTIONS_GHC
pragma? <o:p></o:p></p>
<div>
<p class=MsoNormal>On Sat, Jun 7, 2008 at 9:23 AM, Conal Elliott <<a
href="mailto:conal@conal.net">conal@conal.net</a>> wrote:<o:p></o:p></p>
<p class=MsoNormal>Thanks a million, Lennart! -fno-method-sharing was the
missing piece. - Conal<o:p></o:p></p>
<div>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p>
<div>
<p class=MsoNormal>On Sat, Jun 7, 2008 at 5:07 AM, Lennart Augustsson <<a
href="mailto:lennart@augustsson.net" target="_blank">lennart@augustsson.net</a>>
wrote:<o:p></o:p></p>
<p class=MsoNormal>Here's something that actually works. You need to pass<br>
-fno-method-sharing on the command line.<br>
Instead of using rules on methods it uses rules on global functions,<br>
and these global functions don't get inlined until late (after the<br>
rule has fired).<br>
<br>
-- Lennart<o:p></o:p></p>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
module F where<br>
<br>
-- | Domain of a linear map.<br>
class AsInt a where<br>
toInt' :: a -> Int<br>
fromInt' :: Int -> a<o:p></o:p></p>
</div>
<p class=MsoNormal>{-# INLINE[1] toInt #-}<br>
toInt :: (AsInt a) => a -> Int<br>
toInt = toInt'<br>
<br>
{-# INLINE[1] fromInt #-}<br>
fromInt :: (AsInt a) => Int -> a<br>
fromInt = fromInt'<o:p></o:p></p>
<div>
<p class=MsoNormal><br>
{-# RULES<br>
"toInt/fromInt" forall m . toInt (fromInt m) = m<br>
#-}<br>
<br>
{-# INLINE onInt #-}<br>
onInt :: AsInt a => (Int -> Int) -> (a -> a)<o:p></o:p></p>
</div>
<p class=MsoNormal>onInt f x = fromInt (f (toInt x))<o:p></o:p></p>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
test :: AsInt a => (Int -> Int) -> (Int -> Int) -> (a -> a)<br>
test h g = onInt h . onInt g<br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>2008/6/7 Conal Elliott <<a href="mailto:conal@conal.net"
target="_blank">conal@conal.net</a>>:<o:p></o:p></p>
</div>
<div>
<div>
<p class=MsoNormal>> I'm trying to do some fusion in ghc, and I'd greatly
appreciate help with<br>
> the code below (which is simplified from fusion on linear maps).
I've tried<br>
> every variation I can think of, and always something prevents the fusion.<br>
><br>
> Help, please! Thanks, - Conal<br>
><br>
><br>
> {-# OPTIONS_GHC -O2 -Wall -fglasgow-exts -ddump-simpl -ddump-simpl-stats
#-}<br>
> -- {-# OPTIONS_GHC -ddump-simpl-iterations #-}<br>
><br>
> module F where<br>
><br>
> -- | Domain of a linear map.<br>
> class AsInt a where<br>
> toInt :: a -> Int<br>
> fromInt :: Int -> a<br>
><br>
> {-# RULES<br>
> "toInt/fromInt" forall m. toInt (fromInt m) = m<br>
> #-}<br>
><br>
> {-# INLINE onInt #-}<br>
> onInt :: AsInt a => (Int -> Int) -> (a -> a)<br>
> onInt f = fromInt . f . toInt<br>
><br>
> test :: AsInt a => (Int -> Int) -> (Int -> Int) -> (a ->
a)<br>
> test h g = onInt h . onInt g<br>
><br>
> -- The desired result:<br>
> --<br>
> -- test h g<br>
> -- == onInt h . onInt g<br>
> -- == (fromInt . h . toInt) . (fromInt . g . toInt)<br>
> -- == \ a -> (fromInt . h . toInt) ((fromInt . g . toInt)
a)<br>
> -- == \ a -> (fromInt . h . toInt) (fromInt (g (toInt
a)))<br>
> -- == \ a -> fromInt (h (toInt (fromInt (g (toInt a)))))<br>
> -- == \ a -> fromInt (h (g (toInt a)))<br>
><br>
><br>
><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class=MsoNormal>> _______________________________________________<br>
> Glasgow-haskell-users mailing list<br>
> <a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank">Glasgow-haskell-users@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users"
target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
><br>
><o:p></o:p></p>
</div>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</div>
</body>
</html>