This would be a more convincing argument if I knew how to get more accurate timestamping, but none the less, both the empirical evidence and my (shallow) understanding of GHC internals, support the statement I made--every single function in Haskell is automatically memoized by the compiler--though I should have added a note to the effect that this only works for function calls that are not optimised away.
Er, no. This probably will sound overly technical, but there is not any (what is generally meant by) memoization going on here. It has to do with the way the parser turns the code into a graph, and representing the same graph in the same way. If you kind of squint, you could think of it as a form of compile time memoization, but again, I think that is stretching the terminology. It's the same way that something like...
let x = very_long_computation in x + x
...only takes half as long to execute as you might expect (in the face of referential transparency). Try the following code to convince yourself (enter "100000000" at the prompt).
import System.Time( getClockTime ) add_up 0 acc = acc add_up n acc = add_up (n - 1) (acc + n) time = getClockTime >>= print main = do time print (add_up 10000000 0) time print (add_up 5000000 0) time putStrLn "enter number to add up to..." val <- getLine time print (add_up (read val) 0) time

In reply to Re^6: Doing "it" only once by Anonymous Monk
in thread Doing "it" only once by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.