COMP0020-2020-lecture21-graph Reduction Continued With Captions
COMP0020-2020-lecture21-graph Reduction Continued With Captions
Christopher D. Clack
2020
Lecture 21
GRAPH REDUCTION
continued
@ @ @
@ @ @
+ @ @ @
+ +
@ @ @
f
© 2020 Christopher D. Clack 7
Using a Spine Stack is very fast, with far
FUNCTIONAL PROGRAMMING fewer accesses to heap memory
locations, but uses an unbounded
GRAPH REDUCTION continued amount of memory
Using Pointer Reversal is very frugal with
memory, but is very slow (unless
implemented in hardware)
Using Pointer Reversal is not merely
SPINE TRAVERSAL – Comparison useful for traversing spines (and
argument spines) but also stores
information about how far evaluation
• Using a Spine Stack is very fast, with far fewer accesses has progressed – this can be useful
to heap memory locations, but uses an unbounded when evaluating multiple strict
arguments (with a Spine Stack after
amount of memory evaluating each argument the parent
spine is viewed entirely afresh, with no
such information)
• Using Pointer Reversal is very frugal with memory, but is
very slow (unless implemented in hardware)
@ arg2 arg3
arg1 arg2
S arg1 © 2020 Christopher D. Clack 10
We start with an observation that the
FUNCTIONAL PROGRAMMING (fixed) combinator K is treated like a
built-in function rather than a user-
GRAPH REDUCTION continued defined function, and in particular it is
not evaluated until it has both of its
arguments
• this has nothing to do with the
strictness of those arguments – e.g.
SUPERCOMBINATOR GRAPH REDUCTION the built-in operator "if" is only strict
in its first argument but is not d-
reduced until all three arguments are
• Fixed combinators are treated like operators (not present
evaluated until all arguments are present) • nor does this prevent partial
applications – it is only about the
timing of when evaluation occurs at
• This will also apply to Super-Combinators runtime
This approach will also apply to Super-
Combinators – although their definitions
• We know that Super-Combinators have no free can't be known in advance (as there will
variables, and if they are not evaluated until all be a different set of Super-Combinators
for each program), we can treat them
arguments are present then there can be no need for an like operators and only evaluate them
environment of bindings to be managed at runtime when all arguments are available
Notice that Super-Combinators are (by
definition) combinators and therefore
• Thus, Super-Combinators lead to super-efficient have no free variables, and if they are
implementation using compiled graph reduction never evaluated until all arguments are
present (and their body is not a l
abstraction) this solves the problem
seen in the previous lecture that
required an environment of bindings to
be managed at runtime
Thus, Super-Combinators lead to super-
efficient implementation using compiled
graph reduction
© 2020 Christopher D. Clack 11
This slide gives the definition of Super-
FUNCTIONAL PROGRAMMING Combinators appearing on Page 223
(Section 13.2) of the required-reading
GRAPH REDUCTION continued text book "The Implementation of
Functional Programming Languages", by
Simon Peyton Jones:
A supercombinator $S of arity n is a l
SUPERCOMBINATOR GRAPH REDUCTION expression of the form lx1.lx2 ...
lxn.E
DEFINITION where E is not a l abstraction (this just
ensures that all the ‘leading lambdas’
A supercombinator $S of arity n is a l expression of the are accounted for by x1...xn) such that