The first (very simple) observation is that enhancements should allow
general goals to be added to the base cases of enhancements. For
pedagogical reasons, the original presentation classified enhancements
into different categories according to the kind of goal added to
recursive clauses and only allowed additional unifications to be added
to facts. The limited abstraction simplifies learning but also
restricts the scope of enhancements.
For example, to find the sum of the squares of the leaves of a tree using
foldrbt/4
we could use
foldrbt(plus, square, Tree, SumXX)
,
where
square
takes a number and returns its square. The optimised program (or
enhanced skeleton) would have a call to
square
in the base case.