Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
In the last translation rule, concatMap is defined in the prelude (see page 51) and complP at(p)<br />
denotes the set of patterns that are incompatible with p. This set is defined by<br />
complP at(x) = {}<br />
for all variables x and<br />
complP at(C p1 . . . pn) = {C1 x11 . . . x1n1 , . . . , Ck xk1 . . . xknk }<br />
∪ {C p1 . . . pi−1 p ′ yi+1 . . . yn | 1 ≤ i ≤ n, p ′ ∈ complP at(pi)}<br />
where C, C1, . . . , Ck are all the constructors of the result type of C and all xij, yi are fresh variables.<br />
For instance, complP at([True]) = {[], False:zs, True:y:ys} and complP at((x,y)) = {}.<br />
Note that this translation does not work for patterns containing number constants since in this<br />
case the complement set of patterns is infinite. Therefore, we modify this scheme as follows. If the<br />
pattern p in a list comprehension [e | p en<br />
Note that case expressions use the layout rule (see Section C.2). Thus, the patterns p1, . . . , pn<br />
must be vertically aligned. The informal operational meaning of the case expression is as follows.<br />
Evaluate e so that it matches a pattern pi. If this is possible, replace the entire case expression<br />
by the corresponding alternative ei (after replacing the pattern variables occurring in pi by their<br />
actual expressions). If none of the patterns p1, . . . , pn matches, the computation fails. The pattern<br />
matching is tried sequentially, from top to bottom, and rigid, without binding of free variables<br />
occurring in e. Thus, case expressions correspond to rigid functions. Actually, each case expression<br />
can be translated into an auxiliary function so that case expressions do not increase the power of the<br />
22