[Haskell-cafe] Assignment, Substitution or what?
ok
ok at cs.otago.ac.nz
Tue Oct 2 22:27:42 EDT 2007
On 3 Oct 2007, at 1:42 pm, PR Stanley wrote:
> When a function is declared in C the argument variable has an
> address somewhere in the memory:
> int f ( int x ) {
> return x * x;
> }
Wrong. On the machines I use, x will be passed in registers and will
never ever have an address in memory. In fact, unless I hold the Sun
C compiler back by main force, it will probably open code f() so that
there isn't any f any more, let alone any x. Here's the actual SPARC
code generated for f:
f: retl
mulx %o0,%o0,%o0
No memory, no address.
In C, a function call is rather like entering a new block, declaring
some new variables (which might or might not ever go into memory) and
initialising them to the values of the arguments.
In Haskell, carrying out a function call is rather like creating some
new names and *binding* them to promises to evaluate the arguments
(if they are ever needed) and then returning a promise to evaluate the
body (if it is ever needed). The key point is *binding* names to
(deferred calculations of) values, rather than *initialising*
mutable variables to (fully evaluated) values. How this is done is
entirely up to the compiler.
More information about the Haskell-Cafe
mailing list