<div dir="ltr">Hi,<div><br></div><div>Well at least I hadn't overlooked something obvious!</div><div><br></div><div>Some combination of dummy arguments, NOINLINE and <span style="font-size:12.8px">-fno-full-laziness did indeed prevent it from sharing but this definitely seemed unsatisfactory. Particularly that -fno-full-laziness applies to the whole module which feels a bit heavyweight.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">How feasible would it be to add another pragma like NOINLINE that prevented exactly this? Is it actually important? This is a toy example of course and I've not come across this kind of problem in any real code - has anyone else?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Cheers,</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">David</span></div><div><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 December 2015 at 14:36, Joachim Breitner <span dir="ltr"><<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
Am Freitag, den 18.12.2015, 09:40 +0000 schrieb David Turner:<br>
> Now I'm a bit stuck: how do you prevent this from happening?<br>
> Obviously here we could just implement fibs differently, but as a<br>
> more general question, how would you prevent unwanted sharing from<br>
> taking place?<br>
<br>
</span>floating out (and, relatedly, CSE) is tricky to get a good grip on, and<br>
I wish there were good and easy solutions. This also comes up with<br>
things like "zip xs [0..]" and gets in the way of applying rules.<br>
<br>
Note that in your example, depending on the use case, maybe the<br>
programmer did want to share the fibs list. So it is not clear that the<br>
compiler can always do the right thing.<br>
<br>
You can pass -fno-full-laziness to GHC (and you can do that with a per-<br>
module pragma), this might work in your case, but you better check.<br>
<br>
Another trick is to add an argument to fibs, e.g. the initial starting<br>
values<br>
<br>
fib n = fibs 0 1 !! n<br>
where<br>
fibs a b = go where go = a : b : zipWith (+) go (tail go)<br>
{-# NOINLINE fibs #-}<br>
<br>
The noinline pragma might be required as otherwise GHC will simplify<br>
the code again to your origin form, and then share the go with a and be<br>
specialized to 0 and 1. Again, check the core if it indeed does what<br>
you want.<br>
<br>
Both approaches are unsatisfying.<br>
<br>
<br>
Greetings,<br>
Joachim<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Joachim “nomeata” Breitner<br>
<a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a> • <a href="http://www.joachim-breitner.de/" rel="noreferrer" target="_blank">http://www.joachim-breitner.de/</a><br>
Jabber: <a href="mailto:nomeata@joachim-breitner.de">nomeata@joachim-breitner.de</a> • GPG-Key: 0xF0FBF51F<br>
Debian Developer: <a href="mailto:nomeata@debian.org">nomeata@debian.org</a><br>
<br>
</font></span><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>