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.

A.3 Relational Programming<br />

Here is a traditional example from logic programming: a simple deductive database with family<br />

relationships. We use a relational programming style, i.e., all relationships are represented as<br />

constraints (i.e., functions with result type Success).<br />

-- Declaration of an enumeration type for persons:<br />

-- (as an alternative, one could consider persons as strings)<br />

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

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

-- Two basic relationships:<br />

married :: Person -> Person -> Success<br />

married Christine <strong>An</strong>tony = success<br />

married Maria Bill = success<br />

married Monica John = success<br />

married Alice Frank = success<br />

mother :: Person -> Person -> Success<br />

mother Christine John = success<br />

mother Christine Alice = success<br />

mother Maria Frank = success<br />

mother Monica Susan = success<br />

mother Monica Peter = success<br />

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

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

father :: Person -> Person -> Success<br />

father f c = let m free in married m f & mother m c<br />

grandfather :: Person -> Person -> Success<br />

grandfather g c = let f free in father g f & father f c<br />

grandfather g c = let m free in father g m & mother m c<br />

Expressions and their evaluated results:<br />

father John child ❀ {child=Susan} | {child=Peter}<br />

grandfather g c ❀<br />

{g=<strong>An</strong>tony,c=Susan} | {g=<strong>An</strong>tony,c=Peter} |<br />

{g=Bill,c=<strong>An</strong>drew} | {g=<strong>An</strong>tony,c=<strong>An</strong>drew}<br />

40

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

Saved successfully!

Ooh no, something went wrong!