Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
f ′′ x1 . . . xk y1 . . . ym = let decls1<br />
f1 p = y1<br />
...<br />
fm p = ym<br />
decls2<br />
in e<br />
where x1 . . . xk are all the variables occurring in l, y1 . . . ym are all the variables occurring<br />
in p, z is a new variable symbol, and f ′ , f ′′ , f1, . . . , fm are new function symbols. Repeat<br />
this step for f ′′ until all local pattern declarations are eliminated.<br />
This translation can be optimized in some specific cases. If p is just a variable, the<br />
function f ′ is not needed and the definition of l can be simplified into<br />
l = C[f ′′ x1 . . . xk e ′ ]p<br />
Similarly, if e ′ is a variable, the function f ′ is also not needed and the definition of l can<br />
be replaced by<br />
l = C[f ′′ x1 . . . xk (f1 e ′ ) . . . (fm e ′ )]p<br />
Complete local function definitions:<br />
If a locally declared function f refers in its definition to a variable v not contained in<br />
its argument patterns, then add v as an additional first 23 argument to all occurrences<br />
of f (i.e., left-hand sides and calls). Repeat this step until all locally defined functions<br />
are completed. Note that this completion step must also be applied to free variables<br />
introduced in the same let expression, i.e., the rule<br />
f x = let y free<br />
g z = c y z<br />
in g 0<br />
is completed to<br />
f x = let y free<br />
g y z = c y z<br />
in g y 0<br />
Globalize local function definitions:<br />
If the definitions of all locally declared functions are completed, i.e., the definitions only<br />
refer to variables in the argument patterns, delete the locally declared functions and<br />
define them at the top-level (and rename them if there are already top-level functions<br />
with the same name). For instance, the previous rule is transformed into the definitions<br />
g y z = c y z<br />
f x = let y free in g y 0<br />
Note that the entire transformation process must be applied again to the new top-level<br />
declarations since they may also contain local declarations.<br />
23 The new arguments must come first because of possible partial applications of this function.<br />
76