
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@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org