[Haskell-cafe] Avoid sharing

Joachim Breitner mail at joachim-breitner.de
Mon Nov 7 21:34:23 UTC 2016


Hi,

Am Montag, den 07.11.2016, 16:00 -0500 schrieb Brandon Allbery:
> It's not specified in any standard, but ghc will only share something
> that is directly bound. There is no sensible way to determine sharing
> automatically that will do what everyone expects, so ghc doesn't try:
> the programmer is expected to use bindings to specify sharing.

that is not true. GHC applies „common subexpression elimination“, and
this optimization pass will likely sum up the two occurrences of
"someGenerator s".

In places online it says that only code like

> let x = e in .... let y = e in ....

would be CSEd. But reading the code (CSE.hs) I conclude that also 

> let x = e in .... foo e ....

would get CSEd, which includes the code posted by Michael Roth.


Furthermore, the FloatOut pass may turn 
> … foo e …
into
> let x = e in … foo x …
under certain circumstance, so even a limited form of CSE can apply
here.


In the end, only looking at the Core of a concrete program can help to
answer these questions.

Greetings,
Joachim

-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttps://www.joachim-breitner.de/
  XMPP: nomeata at joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161107/3b61e3f4/attachment.sig>


More information about the Haskell-Cafe mailing list