<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.&nbsp; (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>&nbsp;</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 =&gt; a -&gt; 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>&nbsp;</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>&nbsp;</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 -&gt; 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>&nbsp;</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>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>That is, &#8216;fint&#8217; extracts the &#8216;f&#8217; method
from dCInt::C Int, and it&#8217;s then used repeatedly.&nbsp; <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</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>&nbsp;</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 =&nbsp; ...(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>&nbsp;</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.&nbsp; It shouldn&#8217;t
make much difference, but of course it *<b>does</b>* when rules are involved,
because there are no rules for fint (it&#8217;s a fresh, local function).&nbsp;
<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</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>&nbsp;</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>&nbsp;</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?&nbsp; <o:p></o:p></p>

<div>

<p class=MsoNormal>On Sat, Jun 7, 2008 at 9:23 AM, Conal Elliott &lt;<a
href="mailto:conal@conal.net">conal@conal.net</a>&gt; wrote:<o:p></o:p></p>

<p class=MsoNormal>Thanks a million, Lennart!&nbsp; -fno-method-sharing was the
missing piece.&nbsp; - Conal<o:p></o:p></p>

<div>

<div>

<p class=MsoNormal style='margin-bottom:12.0pt'><o:p>&nbsp;</o:p></p>

<div>

<p class=MsoNormal>On Sat, Jun 7, 2008 at 5:07 AM, Lennart Augustsson &lt;<a
href="mailto:lennart@augustsson.net" target="_blank">lennart@augustsson.net</a>&gt;
wrote:<o:p></o:p></p>

<p class=MsoNormal>Here's something that actually works. &nbsp;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>
&nbsp;-- 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>
&nbsp;toInt' &nbsp; :: a -&gt; Int<br>
&nbsp;fromInt' :: Int -&gt; a<o:p></o:p></p>

</div>

<p class=MsoNormal>{-# INLINE[1] toInt #-}<br>
toInt :: (AsInt a) =&gt; a -&gt; Int<br>
toInt = toInt'<br>
<br>
{-# INLINE[1] fromInt #-}<br>
fromInt :: (AsInt a) =&gt; Int -&gt; a<br>
fromInt = fromInt'<o:p></o:p></p>

<div>

<p class=MsoNormal><br>
{-# RULES<br>
&quot;toInt/fromInt&quot; &nbsp; forall m . toInt (fromInt m) = m<br>
&nbsp;#-}<br>
<br>
{-# INLINE onInt #-}<br>
onInt :: AsInt a =&gt; (Int -&gt; Int) -&gt; (a -&gt; 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 =&gt; (Int -&gt; Int) -&gt; (Int -&gt; Int) -&gt; (a -&gt; 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 &lt;<a href="mailto:conal@conal.net"
target="_blank">conal@conal.net</a>&gt;:<o:p></o:p></p>

</div>

<div>

<div>

<p class=MsoNormal>&gt; I'm trying to do some fusion in ghc, and I'd greatly
appreciate help with<br>
&gt; the code below (which is simplified from fusion on linear maps).
&nbsp;I've tried<br>
&gt; every variation I can think of, and always something prevents the fusion.<br>
&gt;<br>
&gt; Help, please! &nbsp;Thanks, - Conal<br>
&gt;<br>
&gt;<br>
&gt; {-# OPTIONS_GHC -O2 -Wall -fglasgow-exts -ddump-simpl -ddump-simpl-stats
#-}<br>
&gt; -- {-# OPTIONS_GHC -ddump-simpl-iterations #-}<br>
&gt;<br>
&gt; module F where<br>
&gt;<br>
&gt; -- | Domain of a linear map.<br>
&gt; class AsInt a where<br>
&gt; &nbsp; toInt &nbsp; :: a -&gt; Int<br>
&gt; &nbsp; fromInt :: Int -&gt; a<br>
&gt;<br>
&gt; {-# RULES<br>
&gt; &quot;toInt/fromInt&quot; &nbsp; forall m. toInt (fromInt m) = m<br>
&gt; &nbsp;#-}<br>
&gt;<br>
&gt; {-# INLINE onInt #-}<br>
&gt; onInt :: AsInt a =&gt; (Int -&gt; Int) -&gt; (a -&gt; a)<br>
&gt; onInt f = fromInt . f . toInt<br>
&gt;<br>
&gt; test :: AsInt a =&gt; (Int -&gt; Int) -&gt; (Int -&gt; Int) -&gt; (a -&gt;
a)<br>
&gt; test h g = onInt h . onInt g<br>
&gt;<br>
&gt; -- The desired result:<br>
&gt; --<br>
&gt; -- &nbsp; test h g<br>
&gt; -- &nbsp; &nbsp; == onInt h . onInt g<br>
&gt; -- &nbsp; &nbsp; == (fromInt . h . toInt) . (fromInt . g . toInt)<br>
&gt; -- &nbsp; &nbsp; == \ a -&gt; (fromInt . h . toInt) ((fromInt . g . toInt)
a)<br>
&gt; -- &nbsp; &nbsp; == \ a -&gt; (fromInt . h . toInt) (fromInt (g (toInt
a)))<br>
&gt; -- &nbsp; &nbsp; == \ a -&gt; fromInt (h (toInt (fromInt (g (toInt a)))))<br>
&gt; -- &nbsp; &nbsp; == \ a -&gt; fromInt (h (g (toInt a)))<br>
&gt;<br>
&gt;<br>
&gt;<o:p></o:p></p>

</div>

</div>

<div>

<div>

<p class=MsoNormal>&gt; _______________________________________________<br>
&gt; Glasgow-haskell-users mailing list<br>
&gt; <a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank">Glasgow-haskell-users@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users"
target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
&gt;<br>
&gt;<o:p></o:p></p>

</div>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</div>

</body>

</html>