14.11.2012 Views

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

Curry: An Integrated Functional Logic Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

.<br />

if bk then ek else undefined<br />

where decls<br />

Transform where into let:<br />

Each unconditional rule of the form<br />

l = r where decls<br />

is transformed into<br />

l = let decls in r .<br />

Each conditional rule of the form<br />

l | c = r [ where decls ]<br />

is transformed into<br />

l = [ let decls in ] (c|r)<br />

where the meaning of the guarded expression (c|r) is explained in Figure 3. Thus, we assume<br />

in the subsequent transformations that all program rules are of the form “l = r” (where r might<br />

be a let-expression).<br />

Note that this transformation is not really necessary but provides for a unified treatment of<br />

the elimination of local pattern and function declarations in let and where.<br />

Eliminate local patterns and functions:<br />

All local pattern and function declarations in a rule “l = r” are eliminated by iterating the<br />

elimination of outermost local declarations as follows. For this purpose, we denote by r =<br />

C[let decls in e]p an outermost let declaration in r, i.e., there is no prefix position p ′ < p<br />

in r with r|p ′ = let . . .<br />

We apply the following transformations as long as possible to eliminate all local pattern and<br />

function declarations in a rule of the form “l = C[let decls in e]p”:<br />

Eliminate patterns:<br />

Select a local pattern declaration which contains only argument variables from the main<br />

function’s left-hand side in the expression, i.e., the rule has the form<br />

l = C[let decls1<br />

p = e ′<br />

in e]p<br />

decls2<br />

with free(e ′ ) ⊆ free(l) (it is a programming error if no pattern declaration has this<br />

property, i.e., cyclic pattern definitions or pattern definitions depending on locally free<br />

variables are not allowed). Then transform this rule into the rules<br />

l = C[f ′ x1 . . . xk e ′ ]p<br />

f ′ x1 . . . xk z = f ′′ x1 . . . xk (f1 z) . . . (fm z)<br />

75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!