https://wiki.haskell.org/index.php?title=Sharing&feed=atom&action=historySharing - Revision history2017-05-23T10:57:45ZRevision history for this page on the wikiMediaWiki 1.19.14+dfsg-1https://wiki.haskell.org/index.php?title=Sharing&diff=16744&oldid=prevLemming at 15:54, 9 November 20072007-11-09T15:54:17Z<p></p>
<p><b>New page</b></p><div>'''Sharing''' means that temporary data is physically stored, if it is used multiple times.<br />
<br />
In<br />
<haskell><br />
let x = sin 2<br />
in x*x<br />
</haskell><br />
<hask>x</hask> is used twice as factor in the product <hask>x*x</hask>.<br />
Due to [[Referential transparency]] it does not play a role,<br />
whether <hask>sin 2</hask> is computed twice or<br />
whether it is computed once and the result is stored and reused.<br />
However, when you write <hask>let</hask> the Haskell compiler will certainly decide to store the result.<br />
This can be the wrong way, if a computation is cheap but its result is huge.<br />
Consider<br />
<haskell><br />
[0..1000000] ++ [0..1000000]<br />
</haskell><br />
where it is much cheaper to compute the list of numbers than to store it with full length.<br />
<br />
Because the sharing property cannot be observed in Haskell,<br />
it is hard to transfer the sharing property to foreign programs<br />
when you use Haskell as an [[Embedded domain specific language]].<br />
You must design a monad or use [[unsafePerformIO]] hacks, which should be avoided.<br />
<br />
[[Category:Glossary]]</div>Lemming