[Haskell-beginners] Where/Let clauses and subexpression repetition/memoization
Brandon Allbery
allbery.b at gmail.com
Fri Aug 19 21:54:12 CEST 2011
On Aug 19, 2011 12:44 PM, "Tom Murphy" <amindfv at gmail.com> wrote:
> On Fri, Aug 19, 2011 at 2:52 AM, Daniel Fischer <
daniel.is.fischer at googlemail.com> wrote:
>> [...] In most cases, you'll get recomputation,
>> but GHC does a bit of CSE, so in some cases it will compute only once and
>> share the result (which may be a bad thing - that's a further reason for
>> not doing too much CSE, sometimes sharing has catastrophic results).
>
> This is a beginner's list, so I'll ask: what catastrophic result could it
have, if it's computing pure functions?
Catastrophic means nontermination, usually due to the stack or heap getting
blown out. The classic example of catastrophic CSE is one of the simplest:
computing the average of a list that won't fit in memory, such as
[1..100000000000]. CSE, manual or automatic, would hold the entire list in
memory, while manually fusing the sum and count operations over a fold runs
in constant memory. Last I heard, GHC still didn't detect even that simple
case, although it does handle some others.
--
...tabula non rasa. ++bsa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110819/994a1050/attachment.htm>
More information about the Beginners
mailing list