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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A.4 <strong>Functional</strong> <strong>Logic</strong> Programming<br />

This is the same example as in the previous section. However, we use here a functional logic<br />

programming style which is more readable but provides the same goal solving capabilities. The<br />

basic functions are husband and mother which express the functional dependencies between the<br />

different persons. Note that the derived function grandfather is a non-deterministic function<br />

which yields all grandfathers for a given person.<br />

data Person = Christine | Maria | Monica | Alice | Susan |<br />

<strong>An</strong>tony | Bill | John | Frank | Peter | <strong>An</strong>drew<br />

-- Two basic functional dependencies:<br />

husband :: Person -> Person<br />

husband Christine = <strong>An</strong>tony<br />

husband Maria = Bill<br />

husband Monica = John<br />

husband Alice = Frank<br />

mother :: Person -> Person<br />

mother John = Christine<br />

mother Alice = Christine<br />

mother Frank = Maria<br />

mother Susan = Monica<br />

mother Peter = Monica<br />

mother <strong>An</strong>drew = Alice<br />

-- and here are the deduced functions and relationships:<br />

father :: Person -> Person<br />

father c = husband (mother c)<br />

grandfather :: Person -> Person<br />

grandfather g = father (father g)<br />

grandfather g = father (mother g)<br />

Expressions and their evaluated results:<br />

father Child =:= john ❀ {Child=susan} | {Child=peter}<br />

grandfather c ❀<br />

{c=Susan} <strong>An</strong>tony | {c=Peter} <strong>An</strong>tony | {c=<strong>An</strong>drew} Bill | {c=<strong>An</strong>drew} <strong>An</strong>tony<br />

41

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

Saved successfully!

Ooh no, something went wrong!